How to Display (Navigation) Links to Previous and Next Posts on your Blog Entry (WordPress)
Many WordPress themes by default do not have the previous post and next post buttons on the single post page, that is when you open a particular post from the main WordPress blog. If I like a particular post that I come across, its very likely that I’ll dig through the rest of the posts on that blog. And for that, I don’t like to load the blog-home-page each time after reading a blog entry.So, previous and next post navigation-buttons are quite an indispensible features of a blog that I love to see on whatever blog I read.
A template file of a WordPress blog is basically a PHP file and the way your single post page displays is determined by a file called single.php which is present in your \wp-content\themes\yourtheme\ directory. So, you get an idea that for adding the previous and next post links (or buttons, whatever you choose) , we’ll have to edit this file called single.php
Now let’s see how we do it. Take a look at how a most basic single.php file can look like
<!–single.php–>
<!–This is the loop that checks if there are any posts to display. If there’s no post a custom error message is displayed.Else the requested post shows up!–>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><!–This is the navigation that we intend to add to a blog entry. As this is placed above the title of my post (see the next piece of code) , the previous and next buttons appear above the title of my blog post–>
<p><?php previous_post_link(‘« %link |’) ?> <a href=”<?php bloginfo(‘url’); ?>”>Home</a> <?php next_post_link(‘| %link »’) ?></p><!–This shows the post title–>
<h1 id=”post-<?php the_ID(); ?>”><a href=”<?php echo get_permalink() ?>” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”><?php the_title(); ?></a></h1><!–This displays the author name below the title of the post–>
<p><b>By <?php the_author(); ?></b> | <?php the_time(‘F j, Y’); ?></p><!–This part shows the main blog entry–>
<div class=”postspace2″>
</div>
<!–content with more link–>
<?php the_content(‘<p class=”serif”>Read the rest of this entry »</p>’); ?>
<!–for paginate posts–><!–This part is the footer of the blog-post that shows the categories and comments–>
<?php link_pages(‘<p><strong>Pages:</strong> ‘, ‘</p>’, ‘number’); ?>
<p><b>Topics:</b> <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?> <?php comments_popup_link(‘No Comments »’, ’1 Comment »’, ‘% Comments »’); ?></p><div class=”postspace”>
</div>
<!–almost all options over and out–>
The text inside <!– –> in the code are comments that only describe what a piece of code does. I have elaborated them for your convenience, here. They may not be exactly the same in your template.
So what you basically need to add navigation (like on my blog’s single blog entry) is this piece of code:
<p><?php previous_post_link(‘« %link |’) ?> <a href=”<?php bloginfo(‘url’); ?>”>Home</a> <?php next_post_link(‘| %link »’) ?></p>
<?php previous_post_link(‘« %link |’) ?> : This part shows the name of the previous post, hyperlinked to it. The | character after %link shows as | to separate this link from the rest of the links we are going to add. That is link to the home page and to the next post.
<a href=”<?php bloginfo(‘url’); ?>”>Home</a> : This part shows the text Home linked to the home page
<?php next_post_link(‘| %link »’) ?> : This part shows the name of the next post, hyperlinked to it after the | symbol.
This is a simple and very useful navigational aid. But thats not all about it. Only a few people know that this is a good way to improve your internal linking for SEO purposes. Your post will always link to two posts and the homepage with the very appropriate anchor text, that is the title itself.
So, if you don’t have this feature on your blog’s single blog entry page, go ahead, add it as shown above and reap the benefits
I hope this PHP tutorial helps you.









Very good..I think mainly for SEO, because few readers click on those.
Cheers,
Alex.
Alex at Net-Entrepreneur.com’s last blog post..Increasing Blog Stickiness
Thanks for this and for being “do follow”.
RT Cunninghams last blog post..Building Backlinks with Blogs that Do Follow, not No Follow
Perfect, thanks a lot.
VOTED for you at NewsDot
Geoservs last blog post..Trackback?
Hey look at me! I’m spamming your blog with my comment! Can you do the same? – Howie
Now that\’s something to think about. Glad I stopped by – keep up the good work.Ciao!
Cheers for the info, will come in handy with my new website project
Very helpful, and instructive. Thanks a lot, i will surely try this on.
Very convenient code, i would say you did a commendable job by writting and sharing these codes.
This code is really of great help , and linking up is so important in the websites.
thanks for sharing.
wu yi teas latest published blog-post ………. Day Fourteen – Two Weeks and Thirteen Pounds
In addition I would suggest to read some documention about how to create a theme on WordPress official site.
Gregors latest published blog-post ………. Nokia: Global mobile phone market will fall in 2009
Thanks for sharing these codes, i really have a pain writting codes, thanks a lot again !
Very serviceable codes, and they are easy to implement as well.. thanks.
These code proved really useful to me, Time was really limited and i couldn’t write codes so quickly, im glad you shared these codes and i came across it. thanks a lot.
Very beneficial and serviceable codes. thanks alot for sharing.
Hello I need your help!!!!
In my index.php..I confused because i already coded the previous_posts_link()…lines,but I cant see it.Is that possible that I see the the links even in I’m in the local..
Very nice post… this sure is something too technical for people like me, aren’t there any plugins?
UNOBLOGGERs latest published blog-post ………. What are Keywords?
Can you provide more information on this? I was looking for this additional information, just bookmarked to check the updates
thanks alot for sharing
To display the previous and next post links (where the “next” post is a .. that will display the navigation only if a previous or next entry exists, plugin WP-PageNavi, que, no caso do modelo de índice do blog.
First time i tried it didn`t work (I blew it somewhere), so i tried again. And it worked. Thanks.
Ah, great post. I do not do this on my blog and I should. It entices the reader to stay on your blog. Thanks for the how-to!
Great tutorial brother. Working perfectly with my wodpress blog 2.7
Asifs latest published blog-post ………. GreenPhone | Battery Extender | Nokia
Hello…
I am working on PHP. I will defiantly use your tips for creating my blog. You have give very nice information. Thanks for sharing with us such a nice post.
Joomla Expert
Wow………….,nice post
I can see you have put a lot of work into it.I have being reading your posts about. I can see how this benefits everyone.Thankyou
A very informative and nice post. Thanks for sharing with us.
.-= propertyforsalejavea´s last blog ..Property For Sale In Javea =-.
very interesting post and very usefull
thank you for sharing
.-= el acido folico´s last blog ..¡Hola, mundo! =-.
Interesting, never hear this before but don’t assume that just because you agree with.
.-= MacPress´s last blog ..Hello world! =-.
Interesting, never hear this before but don’t assume that just because you agree with.
dealing with wordpress is sometimes easy but this is interesting. thanks
.-= Magazin Haberleri´s last blog ..Leona Lewis’e Saldırı! =-.
Is it an open source project or not? ,
There is a place for Head Start. ,
What connectivity will they have? ,
Broil until cheese is browned and zucchini is barely tender, about 5-7 minutes. ,
very interesting post and very usefull thank you for article.
.-= msn adresleri´s last blog ..Cinsel uyarıcı ve hormon dengeleyici =-.
This is one of the features that are being neglected by webmasters. I’ll definitely add this buttons in my blog. Thanks for the code.
.-= Lea´s last blog ..Resellers =-.
Thanks, the info was helpful because i use wordpress to make some of my blogs.
.-= Chris – Bermuda Triangle´s last blog ..Thermometer Clocks =-.
Post that you have posted is very useful, can we use it in blogspot.please reply..thanks
Thank you for your informative article and comments
LOL – love the phrase ‘mango-fu’ – gonna use both the phrase and the technique myself now
.-= Moto Kurye´s last blog ..Yıldız Kurye =-.
nice article,thanks for the tips .. they were useful like the everyone said
I’ll try to apply this type of programming in my next project. Thanks for sharing this info.
I really enjoyed your article, I tweet!
Leave your response!
Subscribe via Email
Subscribe in a Reader
Most Commented Posts
Comments Policy
Log in
Arthemia by Michael Jubel
Customized by Abhinav Sood @ Inspirit Blog
Entries | Comments (RSS)