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.

</pre>
<div></div>
<pre>
 

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' );
else
$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.

30 Comments

  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
    girl.

  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.

    Thanks.

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

  12. Posted August 21, 2014 at 7:36 am | Permalink

    Please let me know if you’re looking for a author for your blog.
    You have some really good posts and I feel
    I would be a good asset. If you ever want to take some of the load off,
    I’d love to write some articles for your blog in exchange for a link back to mine.
    Please send me an email if interested. Kudos!

  13. Posted August 22, 2014 at 2:47 am | Permalink

    Hello, its fastidious paragraph on the topic of media print, we all understand media is
    a fantastic source of data.

  14. Posted August 22, 2014 at 10:06 pm | Permalink

    It’s going to be finish of mine day, but before ending I am reading this impressive paragraph to improve my experience.

  15. Posted August 22, 2014 at 11:03 pm | Permalink

    Very nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog
    posts. After all I’ll be subscribing to your feed and I hope you write again soon!

  16. Posted August 22, 2014 at 11:09 pm | Permalink

    An outstanding share! I’ve just forwarded this onto a co-worker who has been conducting a little homework on this.

    And he in fact ordered me dinner due to the fact that
    I stumbled upon it for him… lol. So let me
    reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to discuss this subject here on your web
    site.

  17. Posted August 23, 2014 at 6:13 pm | Permalink

    Dehydration and exposure to heat can lead to a number of severe health
    risks in people and pets. As a house owner your job is to settle on a trustworthy company that can provide efficient
    service at an affordable price. Students who attend city
    colleges often do so to acquire an associate’s degree and many tend to pursue state colleges or universities to earn a bachelor’s degree.

  18. Posted August 24, 2014 at 6:30 pm | Permalink

    Do you have a spam problem on this website; I also am a blogger, and
    I was wondering your situation; we have created some nice procedures
    and we are looking to trade strategies with others, why not shoot me an e-mail
    if interested.

  19. Posted August 25, 2014 at 5:10 am | Permalink

    Thanks for finally talking about > Improved separation of comments and pingbacks in Thematic 1.0.1 < Loved it!

  20. Posted August 25, 2014 at 7:50 am | Permalink

    I blog frequently and I seriously appreciate your content.

    This great article has really peaked my interest.

    I’m going to bookmark your website and keep checking for new details about once a week.
    I opted in for your RSS feed as well.

  21. Posted August 25, 2014 at 2:23 pm | Permalink

    We stumbled over here different page and thought I might as well check things out.
    I like what I see so now i am following you. Look forward to
    finding out about your web page for a second time.

  22. Posted August 25, 2014 at 6:21 pm | Permalink

    I love what you guys tend to be up too. This sort of clever work and
    coverage! Keep up the fantastic works guys I’ve you guys to
    my blogroll.

  23. Posted August 28, 2014 at 4:08 am | Permalink

    Greetings, I think your website might be having
    browser compatibility problems. Whenever I look at your web site in Safari, it
    looks fine but when opening in I.E., it’s got some overlapping issues.
    I just wanted to give you a quick heads up! Apart from that, wonderful blog!

  24. Posted August 28, 2014 at 8:29 pm | Permalink

    What’s up everyone, it’s my first pay a visit at this website, and paragraph is genuinely fruitful for me, keep up posting these articles.

  25. Posted August 29, 2014 at 7:46 am | Permalink

    I have to thank you for the efforts you’ve put in penning this blog.
    I really hope to view the same high-grade blog posts
    from you later on as well. In fact, your creative writing abilities has inspired me to get my very own website now ;)

  26. Posted August 29, 2014 at 8:39 am | Permalink

    Excellent beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog site?

    The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept

  27. Posted August 30, 2014 at 1:58 am | Permalink

    Wonderful web site. Lots of useful information here.

    I am sending it to some friends ans also sharing in delicious.

    And naturally, thank you to your effort!

  28. Posted August 31, 2014 at 1:04 pm | Permalink

    Currently it looks like WordPress is the best blogging platform
    out there right now. (from what I’ve read) Is that what you are using on your blog?

  29. Posted September 1, 2014 at 2:06 am | Permalink

    Hi there mates, how is everything, and what
    you desire to say concerning this paragraph, in my view its really
    awesome in support of me.

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>