Improved separation of comments and pingbacks in Thematic 1.0.1

In previous versions of Thematic, the code to separate pingbacks and trackbacks has been based on this article by Ian Stewart. In that article he laments that comments and trackbacks are displayed in the same list by default and shows how to separate them in the comments template. The article was written in 2009, but the principle is common. Use a counter variable to count the number of comments and trackbacks and then make two separate loops to display them. The problem lies in that the paginate_comments_link() function only gets called on the comments list. There are no pagination links for the trackbacks.

Say you have 8 comments and 15 trackbacks, and you have set WordPress to display a maximum of 5 comments per page. That would give you 2 comment-pages and 3 trackback-pages, which is 13 responses = 5 pages altogether. But since we are separating the trackbacks from the pingbacks and the pagination links only were for the comments, the pagination would only show 2 pages and any trackback-pages beyond that would not be reachable. And on top of that, WordPress keeps track of the number of comment-pages internally so that when someone adds a comment they would be redirected to comment-page number 5 – which would be completely empty!

All of this has been addressed in the release of Thematic 1.0.1. For those of you who want to know how it’s done…

Separating comments and trackbacks

Let’s start with looking at some code. This snippet comes from the beginning of the comments loop.

// Collect the comments and pings
$thematic_comments = $wp_query->comments_by_type['comment'];
$thematic_pings = $wp_query->comments_by_type['pings'];

// Calculate the total number of each
$thematic_comment_count = count( $thematic_comments );
$thematic_ping_count = count( $thematic_pings );

// Get the page count for each
$thematic_comment_pages = get_comment_pages_count( $thematic_comments );
$thematic_ping_pages = get_comment_pages_count( $thematic_pings );

// Determine which is the greater pagination number between the two (comment,ping) paginations
$thematic_max_response_pages = ( $thematic_ping_pages > $thematic_comment_pages ) ? $thematic_ping_pages : $thematic_comment_pages;

// Reset the query var to use our calculation for the maximum page (newest/oldest)
if ( $overridden_cpage )
set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? $thematic_comment_pages : 1 );

First of all, there’s no need to have a counter in the comment loop to see how many comments and trackbacks you have. We can grab them directly from the query and count them. Pings are both trackbacks and pingbacks, they will be in the same list.

The get_comment_pages_count() function will calculate the number of pages for us, taking into account both the threading of the comments and the user seleted number of comments per page. We save the largest page number in a variable for later use.

The last bit is there to make sure the correct comment page is shown based on whether you have selected to show the newest or oldest comments first in your discussion settings. The $overridden_cpage variable is a global set by WordPress that decides which comment page to get by default.

Further down, we use our variable in the call to paginate_comments_link.


One more thing

Remember that WordPress keeps track of the number of comment-pages so that it sends new comments to the latest comment-page? We need to tell WordPress to re-calculate the comments-pages. Turns out we can filter get_comment_link.

function thematic_get_comment_link( $link , $comment, $args ) {
global  $wp_rewrite;

$args['type'] = 'comment';
$args['page'] = get_page_of_comment( $comment->comment_ID, $args );

if ( $wp_rewrite->using_permalinks() )
$link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
$link = add_query_arg( 'cpage', $args['page'] , get_permalink( $comment->comment_post_ID ) );

return $link;
add_filter( 'get_comment_link', 'thematic_get_comment_link', 10, 3 );

The important bit here is

$args['type'] = 'comment';

This makes sure that the comment-paging calculations will be done on comments only (and not trackbacks) and send the visitor to the correct place. This will also send them to the correct comment-page after replying to someone else’s comment.

So there you have it! There is still room for some fine-tuning of details, but our testing indicates that it works like it should. Hopefully not too many people were affected by the previous behaviour, but for those who were this update will be very welcome.


  1. Posted June 30, 2012 at 12:45 am | Permalink

    There doesn’t seem to be a changelog available for Thematic 1.0.2 – could you post some details about that please?

    • middlesister
      Posted July 5, 2012 at 3:09 pm | Permalink

      The changelog can be found in the readme. There is not too much change from 1.0.1. New filters for header and footer open and close tag, addition of a couple of language files, pot file in sync again, and the moving of thematic_doctitle to be added as a filter to wp_title. This was to comply with theme review guidelines for wp 3.4.

  2. Posted July 13, 2014 at 10:30 pm | Permalink

    Wonderful items from you, man. I have remember your stuff previous to and you are just too fantastic.

    I really like what you’ve bought here, certainly like what you are stating and the way
    through which you are saying it. You are making it
    entertaining and you continue to care for to keep
    it sensible. I can’t wait to read much more from you.
    That is actually a terrific site.

  3. Posted July 16, 2014 at 3:46 am | Permalink

    Because the admin oof this website is working, no doubt very rapidly it will be renowned, due to its
    feature contents.

  4. Johng657
    Posted July 19, 2014 at 8:31 am | Permalink

    Very nice post. I certainly appreciate this website. cbdeffkdafbd

  5. Posted July 30, 2014 at 12:42 pm | Permalink

    By choosing products that have been tested and approved by a dermatologist to significantly
    reduce the likelihood of damage to the skin and, more importantly, greatly increases the likely hood that you are
    investing in a product that provides desirable results.
    If you already have lines and wrinkles it helps to remove them.
    And because certain vitamins and minerals react with others, and with medicines, it is important to discuss your choices with a doctor, nutritionist, or other healthcare professional to create a program tailored
    to your personal needs.

  6. Posted August 5, 2014 at 10:10 pm | Permalink

    Most men are not into gifts actually, but because you took effort in preparing
    unique presents for them, their prospective may likely to
    change. So this is why I will be bulk buying some velvet cushions and anything else I happen to notice that is
    nice and on offer, as. So if his or her birthday is just round the corner,
    and you are hunting for a special gift, here are a few unique birthday gifts ideas that are sure to delight the birthday boy or

  7. Posted August 8, 2014 at 1:14 pm | Permalink

    Because of the pitfalls associated with erroneous VAT Returns it is worth outsourcing the function to someone who is experienced,
    knowledgeable and up to date with current VAT rules
    and regulations, as well as how to treat specific items.
    Those are some of the key points that I would identify that you would want to find in accountants in Las Vegas.
    These individuals provide the best Tax Filing Support and will be able to
    help stop tax liens and in addition enable you to prevent tax levy difficulties like a Wage Levy or a Bank Levy from the IRS.

  8. Posted August 9, 2014 at 7:37 pm | Permalink

    Pests like cockroaches, spiders, rats, Wasps and
    bees, termites, etc can be spotted in any corner of the world.
    Infestations caused by creatures must not be ignored nor overlooked.
    If you already have a pest infestation, visit their site at to get a
    free estimate.

    Feel free to visit my page – pest control Philadelphia

  9. Posted August 10, 2014 at 2:38 pm | Permalink

    It is easy to install and it makes blogging quick and easy even for a beginner who is without any technical skills.

    So, why shouldn’t you be cashing in too inside online money making industry, well that is because you do not know
    the techniques to success yet. Why not create additional revenue streams so you won.

  10. Posted August 12, 2014 at 11:00 pm | Permalink

    Nowadays, all the manufacturers of these parts are well established even though some people were apprehensive about a few of them when they first started producing them.
    The relationship that they have with the manufacturer largely determines if they can do this.
    When you are exposed, on the basis of an error you’ve committed,
    then you’re “only human.

  11. Posted August 18, 2014 at 5:29 pm | Permalink

    I will rigyht away grasp your rss as I can’t in findin your e-mail
    subscription ink or newsletter service. Do you’ve any?
    Kindly let me know in order that I could subscribe.


    Feel free to surf to my site – Great Low Carb Diets

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <blockquote cite=""> <cite> <code> <em> <strong> <pre class="" title=""> <p> <del> <ins> <ul> <ol> <li>