
With the previous_posts_link() and next_posts_link() functions, WordPress allows you to link previous and next pages. But if the reader reached out the last page, what about providing him a link to the blog archive instead of nothing?

With the previous_posts_link() and next_posts_link() functions, WordPress allows you to link previous and next pages. But if the reader reached out the last page, what about providing him a link to the blog archive instead of nothing?
This recipe is extremely easy to implement : open you index.php file and replace your current navigation by the following:
<?php if ($paged > 1) { ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php } else { ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><a href="http://perishablepress.com/press/archives/">Site Archives »</a></div>
</div>
<?php } ?>
Thanks to Jeff Starr and Chris Coyier for this useful idea! Have you read their book? If no, I definitely recommend it (read review here)
9 Responses
We can use WP Pagenavi for another solutions
It’s very good solution, I will change this recipe to make it do a link for the archive when it’s the last page too.
So Thanks…
that’s a clever idea to keep those viewers who’ve reached the end of your site busy
Excellent
Very nice recipe indeed, helped a lot!
Thanks
I’m looking for exactly something like this, becouse i didn’t know how to change this.
thanks
Masa Cukrowa
Hi,
I do not yet try to apply your recipe. For a long time, I have used WP Pagenavi. I really enjoy this WP plugin. Visitor can easily jump from some page to another one or from page 1 to the last page or the reverse.
Yeah, It’s excellent. It will keep my visitor not going out of my blog. With better navigation, my visitor will move around just in my blog.
Thanks for your sharing.
Trackbacks: