Home > wordpress > WordPress “previous | next post” links!

WordPress “previous | next post” links!

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 – http://codex.wordpress.org/Template_Tags/previous_post_link

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.

Advertisements
Categories: wordpress Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: