Hi. I’m Dre Armeda. I'm a Harley enthusiast, and a Chargers fan. I wear many hats, and love tacos. I'm infatuated with WordPress, web design, and web security. I work at Sucuri Security. I hope to help make the web a safer place!
post

WordPress 2.7 Nested Comments With Separate Ping List

I spent a good portion of the weekend working on the Rank the Cloud theme for its upcoming launch. Most of Saturday was spent on creating aesthetically pleasing nested comments, I was aiming at something easy to understand and use.

With WP 2.7, the wp_list_comments function was introduced and although challenging to use at first, I found it to be a great way to style and configure your post comments.

Matt at Sivel.net composed a great article which I found to be the easiest way to get nested comments working in your themes as well as separating your trackbacks/pings from your comments. He also lists some other great resources to get you moving in the right direction.

This is the comment loop in comment.php that worked in my case:

< ?php if ( have_comments() ) : ?>
	< ?php if ( ! empty($comments_by_type['comment']) ) : ?>
	<h3 id="comments">< ?php comments_number('No Responses', 'One Response', '% Responses' );?></h3>

	<ul class="commentlist">
	< ?php wp_list_comments('type=comment'); ?>
	</ul>
	< ?php endif; ?>

	< ?php if ( ! empty($comments_by_type['pings']) ) : ?>
	<h3 id="pings">Trackbacks/Pingbacks</h3>

	<ul class="pinglist">
	< ?php wp_list_comments('type=pings&callback=list_pings'); ?>
	</ul>
	< ?php endif; ?>

	<div class="navigation">
		<div class="alignleft">< ?php previous_comments_link() ?></div>
		<div class="alignright">< ?php next_comments_link() ?></div>
	</div>
 < ?php else : // this is displayed if there are no comments so far ?>

	< ?php if ('open' == $post->comment_status) : ?>
		<!-- If comments are open, but there are no comments. -->

	< ?php else : // comments are closed ?>
		<!-- If comments are closed. -->
		<p class="nocomments">Comments are closed.</p>

	< ?php endif; ?>
< ?php endif; ?>

I chose to remove the trackbacks/pings out of the comment list and use an unordered list to display links.

Based on Matt’s post, here are the functions I used in functions.php

function list_pings($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment;
?>
        <li id="comment-<?php comment_ID(); ?>">< ?php comment_author_link(); ?>
< ?php }

add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
	global $id;
	$comments_by_type = &separate_comments(get_comments('post_id=' . $id));
	return count($comments_by_type['comment']);
}

Here are few links that helped me as well:

Be aware, some of these posts are a few months old, even prior to the 2.7 release. They are still helpful and will give you the proper guidance needed.

Have a great week.

~Dre

Comments

  1. Angellaa says:

    Hmm, very cognitive post.
    Is this theme good unough for the Digg?

  2. dremeda says:

    Thanks for the comment and sorry for the delay. This theme should be Digg proof so if you feel fit to Digg it, thank you in advance.

  3. sahas says:

    Have you tried this separating code with Paged Comments enabled? It’s a disaster! It works, but some pages are always blank…

Speak Your Mind

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.