I’ve written another plugin for WordPress 1.2, this time to generate the “Next Page” and “Previous Page” links at the top of this page. Actually, you can put them on the top, or on the bottom, or even in the side bar! It works to give you multiple pages of post archiving not just on the front page, but on each of your category archives, as well as on each of your date-based archives (assuming you have enough posts). I’m sure that a lot of WordPress users are wondering why I needed a plugin for that, since there is supposedly an option for it …

Well, the plain fact is, you have to edit your index.php page to get the links to show up, and when I tried the suggestions which were given on the support forums I got lots of database errors. I eventually did get the links to show up, but still with an error message. But even worse for me, was the fact that the links use query style strings instead of friendly URL’s.

I can understand using the queries in this case, since clearly, we don’t really care if the extra pages are visible to search engines, but it really didn’t fit in with the rest of my links. So I fixed it by writing this plugin


To use the plugin, you have to have “posts paged” chosen on your Front Page settings, and you’ll need to add some rules to your .htaccess if you want the pretty links (it could still work with query-style strings: ?paged=3 and so on).

So, you need to add the following rules (or ones like them) to the top of your .htaccess rewrite rules. Note that there are only 4 rules, one of them is line wrapped, but should be on one line in your files (each line starts with “RewriteRule”).

RewriteRule ^category/?(.*)/?page/?([0-9]{1,})?/? /index.php?category_name=&paged= [QSA,L]
RewriteRule ^author/?([^/]*)/?page/?([0-9]{1,})/? /index.php?author_name=&paged= [QSA,L]
RewriteRule ^([0-9]{4})/?([0-9]{1,2})?/?([0-9]{1,2})?/?page/?([0-9]{1,2})?/?$ /index.php?year=&monthnum=&day=&paged= [QSA,L]
RewriteRule ^page/?([0-9]{1,})/?$ /index.php?paged= [QSA,L]

If you don’t want to do that, or your server doesn’t support mod_rewrite, you’ll want to set the variable

$page_default = $page_querystring
in the plugin before installing it.

Then of course, you have to add code to your index.php to get the links:

<?php previous_index_page_link(); next_index_page_link(); ?>

They have classes applied: previousposts and nextposts, so that you can style them however you like, and you can optionally pass each of those functions the text that you want displayed in the link. For an example, here’s my styles:

div.indexpagenavlinks {
     height: 1em;
     display: block;
 }
div.indexpagenavlinks .previousposts {
     text-align: left;
     float: left;
 }
div.indexpagenavlinks .nextposts {
     text-align: right;
     float: right;
 }
 

If you’re still interested in trying it out [;-)] you can download it for yourself