WordPress 2.7 and the comment pager

Tagged WordPress

Comment paging is a great new feature in WordPress 2.7. However, how do you not display the pager when there are no previous or next comments? After digging through the code for quite a while and chatting with some people here’s a solution:

<?php
if ( have_comments() ) { ?>
    <ol class="commentlist">
    <?php
    wp_list_comments();
    if ( get_option('page_comments') && (
        get_query_var('cpage') > 1 ||
        get_query_var('cpage') < get_comment_pages_count() ) ) {
            ?> <!-- pager HTML --> <?php
            next_comments_link();
            ?> <!-- pager HTML --> <?php
            previous_comments_link(); 
            ?> <!-- pager HTML --> <?php
    } ?>
    </ol>
<?php
} ?>

If you want to get started with 2.7 theme migration have a look at Otto’s or Matt’s posts on the new comment system and ping/comment separation.

Update: No, get_previous_posts_page_link() is incorrect and get_previous_comments_link() doesn’t exist (yet).

Update 2: Thanks to Viper007Bond for pointing me in the right direction.

Update 3: trac ticket

Update 4: Additional conditional to not show the pager at all if paging isn’t enabled.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. How to add support for navigation menus to your WordPress theme
  2. Creating a valid WordPress theme
  3. Moving WordPress comments
Leave a Reply

Your email is never shared. Required fields are marked *

*
*