
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)
2 Responses
“But if the reader reached out the last page, what about providing him a link to the blog archive instead of nothing?”
Actually, the link to the archive will appear on the first page, not on the last. I came up with this: http://snipplr.com/view/56903/wordpress-navigation-show-link-to-the-archives-on-the-last-page/. Works for me.
Where i can found wordpress navigation between posts without “older entries”. With 1|2|3|….|55|
Trackbacks: