Post Pic

WordPress tip : Better page navigation

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('&laquo; Older Entries') ?></div>
		<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
	</div>

<?php } else { ?>

	<div class="navigation">
		<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
		<div class="alignright"><a href="http://perishablepress.com/press/archives/">Site Archives &raquo;</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

Jul 20 2011 09:37

“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.

Aug 18 2011 10:58

Where i can found wordpress navigation between posts without “older entries”. With 1|2|3|….|55|

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox