WordPress.org

Ready to get started?Download WordPress

Forums

Post Navigation - Hide last previous link (5 posts)

  1. dyrk
    Member
    Posted 3 years ago #

    Hi

    I've got an ajax post navigation that's working well - except that it shows a previous link on the last page...which, when clicked, obviously leads to a 404 - is there any way to hide the previous link on the last page?

    Here's my code:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $whatever = new WP_Query;
    $whatever->query('post_type=whatever&posts_per_page=10&paged='. $paged);
    ?>

    and then the post navigation:

    <div class="navigation">
    <div class="prev"><?php next_posts_link('PREVIOUS', '1000' ); ?></div>
    <div class="next"><?php previous_posts_link('NEWER', '1000' ); ?></div>
    </div>

    Thanks in advance

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    the '1000' seems to be causing it; without this 'max-pages' parameter, the last link will automatically not be shown.

    http://codex.wordpress.org/Function_Reference/previous_posts_link

    if you can work without restricting the links to a max number, use:

    previous_posts_link('NEWER');

  3. dyrk
    Member
    Posted 3 years ago #

    Hey

    Thanks for the reply. It seems that if I remove the number and just have:
    <?php previous_posts_link('PREVIOUS'); ?>
    nothing happens. They don't show at all.

    Any thoughts on this?

    Many thanks

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    could be an interaction with some plugins, or due to the programming of the theme; maybe the theme is using one of the variable names that are used in the next/previous posts link code.

    as for the plugins, you could try and deactivate all plugins; and if it works then, reactivate one plugin after the other until to find out which might be causing it.

  5. JonMasterson
    Member
    Posted 3 years ago #

    A workaround...

    <div class="navigation">
    <?php if ($wp_query->max_num_pages > $paged) : ?>
    <div class="prev"><?php next_posts_link('PREVIOUS', '1000' ); ?></div>
    <?php endif; ?>
    <div class="next"><?php previous_posts_link('NEWER', '1000' ); ?></div>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic