WordPress 2.7 and the comment pager

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.

0 comments

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.