Archive for June, 2008

WordPress “previous | next post” links!

June 29, 2008 Leave a comment

Hello world! – My first post will be on how to put previous and next post link on the individual post. Why? Obviously, in a normally installed wordpress copy when you comment on a post or click on a post, you reach a place from where you don’t know how to act. To the wordpress bloggers – Many of your viewers have a tendency of closing the tab and running away from your blog. Why scare them away ! Instead link your individual post page with the previous and next posts 🙂

Here is how to do it –
Add these lines of code in the index.php file after the following line (wordpress 2.5.1)-
while (have_posts()) : the_post();

<?php if ($single) { ?>
<div class="navigation"><?php previous_post_link('« « % |', '', 'yes');?> <a href="/"> Home </a> <?php next_post_link('| % » » ', '', 'yes');?></div>
<?php } ?>

More documentation help if required for more cleanliness and flexibility can be found here –

PS: writing a “code” in wordpress is a real big job. By default, WordPress will convert unrecognized uses of < and > into characters which actually look like < and >, which will “look” like a when posted. Or, if it finds the use of an HTML tag within the post, it will use the tag like it is HTML and you will have funky looking text and a messed up layout.

PS2: Use of previous_post is deprecated and previous_post_link should be used instead.

Categories: wordpress Tags: , , ,
%d bloggers like this: