WordPress theming: pushing trackbacks down

I was playing around with my comments section as I wanted to style trackbacks differently from “normal” comments, and while playing around, I decided to just bump them down. The problem with the trackbacks was that they were interfering with the comment discussion. And as I want to keep that discussion as lively as possible, moving the trackbacks out of it was the best step…

Moving them out is actually quite easy. You normally have one foreach block for the comments. Now you make one like this for the normal comments:

foreach ($comments as $comment) :
if ($comment->comment_type == 'comment') {

And add one below that for the trackbacks and pingbacks like this:

foreach ($comments as $comment) :
if ($comment->comment_type != 'comment') {

Because you now have two different loops, you can style them differently as well!


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

5 Responses

  1. Andrei SerdeliucBy Andrei Serdeliuc on 5 July, 2007

    or instead of making 2 foreach’s … you could just do inside the first foreach:
    if($comment->comment_type == ‘pingback’)
    //pingback comment
    //normal comment

  2. JWBBy JWB on 10 July, 2007

    Thanks for the useful information!

  3. DieselBy Diesel on 15 March, 2008
  4. paulBy paul on 3 November, 2008

    Don’t suppose you fancy writing a plug in or tutorial for this do you Joast? I’m having difficulty getting my head round it but also displying the correct counts for when there’s no comments but several pingback etc.


  1. [...] WordPress theming: pushing trackbacks down php code snippet to separate comments from trackbacks (Joost De Valk) (tags: wordpress themes code php comments commenting trackback) [...]