• I’ve got this function:

    <?php next_posts_link( __( ‘<span class=”meta-nav”>←</span> Older posts’) ); ?>

    It creates a link if there are older posts. How do I do something on the condition that there are no older posts? Anything I do that uses this function only seems to echo the link.

Viewing 2 replies - 1 through 2 (of 2 total)
  • russelluresti

    (@russelluresti)

    I couldn’t find a very easy way to do this either, so I just copied what WordPress was already doing in get_next_posts_link().

    <?php
        if ( !$max_page ) $max_page = $wp_query->max_num_pages;
    
        if ( !$paged ) $paged = 1;
    
        $nextpage = intval($paged) + 1;
    
        if ( !is_single() && ( $nextpage <= $max_page ) ) {
    ?>

    That block evaluates to true if there ARE more posts to show — so in here I have my call to next_posts_link(‘More’). If you want to do something when there aren’t any more posts to show, just put in an “else” clause after the last “if”.

    You may call ‘get_next_posts_link’ instead of ‘next_posts_link’.
    A zero-length string returned means there are no previous posts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If Next_Posts_Link is Null?’ is closed to new replies.