Digging Into WordPress
|
In WordPress, there are three ways to respond to a post: you can leave a comment, leave a trackback, or just link to the post to create a pingback. When displaying all of the responses to your posts, it’s a good idea to separate the comments from the pingbacks and trackbacks. Uninterrupted comment threads are a pleasure to read, as are well-styled lists of pingbacks. This is an excellent way to improve the usability, organization, and stylishness of your comment areas. In this DiW tutorial, you’ll learn how to separate your responses and display the comment count for each type. Here is a diagram to help visual the goal:
As you can see, separating these lists gives us a cleaner comments area, making things easier for everyone. Even better news is that we’re going to set it up in two steps. If you would rather group the pingbacks and trackbacks and just segregate the comments, just a few tweaks and you’re off to the races. First let’s see how to separate everything, then explain the grouping of pingbacks and trackbacks before wrapping things up. Step 1 – Display separate comments, pingbacks, and trackbacksThe first thing we need to do is separate the different response types. Fortunately, WordPress makes this very easy. First, open your them’s
This code will enable WordPress to segregate and count each of the different response types using the
This symmetrical slice of code will output the following markup, assuming that the post actually has all three types of responses:
When one of the different response types doesn’t exist on the post, that section will simply be omitted from the markup, keeping things nice and clean. Step 2 – Display separate response countsNow, to display the count for each of these response types, we can call upon the
Each of these lines displays a number corresponding to a specific response type. These response counts may be integrated into our previous code to give us the final result:
That’s the magic bullet right there. Used as your comments loop, this code will display separate comments, pingbacks, and trackbacks, with each showing their respective number of responses in its heading. Notice we threw in some additional code there to make everything completely plug-n-play. Bottom line: slap it in and test it yourself. Should work perfectly for all WordPress 2.7 and better. Separate comments from both pingbacks and trackbacksNote that, alternately, you could segregate comments from both pingbacks and trackbacks, such that your comments display would show something like this: |
3 Responses
Really nice and impressive blog i found today.




![[ Separated display of comments, pingbacks and trackbacks ]](http://digwp.com/wp-content/blog-images/comments-pingbacks.gif)
nice share, good
article, very usefull for me…thank you