Post Navigation – Hide last previous link
-
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
-
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');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
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.
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>
The topic ‘Post Navigation – Hide last previous link’ is closed to new replies.