scriptygoddess

23 May, 2004

"Previous Post | Home | Next Post" links in wordpress

Posted by: Jennifer In: WordPress: Lessons Learned

Charlene just mentioned this in the comments of another post, so I thought I'd post how I'm doing it on my pages (or will be doing it – once I finish them all)

After the "WordPress Post loop" begins (which starts like this) :

<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

Put this:

<?php if ($single) { ?>
<?php previous_post('% |',",'yes') ?> <a href="<?php bloginfo('url'); ?>">Home</a> <?php next_post('| %',",'yes') ?>
<?php } ?>

post updated 5/29/04 to include a few of the suggestions in the comments.

30 Responses to ""Previous Post | Home | Next Post" links in wordpress"

1 | KO

May 23rd, 2004 at 3:12 pm

Avatar

Is there a way to go next and previous in the same category as the post? this method will go to the next post by date – I would like to have it work so it goes to the next post by date in the same category.

2 | kristal

May 23rd, 2004 at 4:40 pm

Avatar

you are brilliant. thank you!!

3 | Jennifer

May 23rd, 2004 at 5:01 pm

Avatar

KO – I would think so… I see a plugin in the future 😉 (But I can't guarantee when…)

4 | Jennifer

May 23rd, 2004 at 5:03 pm

Avatar

Actually – it looks like you can pass a variable into those functions…

here's the function definition:

previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories=")

5 | Jennifer

May 23rd, 2004 at 5:06 pm

Avatar

See this page for previous post

and this page for next post

It's already in there – no plugin needed. Yee ha! 😀

6 | KO

May 23rd, 2004 at 5:44 pm

Avatar

Thats just brilliant!

In MT i had to write a bunch of really ugly php code to get this working…

In WP, will you still need that enter-number-to-post-comment box?

7 | FilSchiesty

May 25th, 2004 at 12:18 am

Avatar

This is a pain. For some reason I cannot implement this code. I dont recieve any errors but my pages dont contain the links.

After tinkering for a while, I did get the "Home" like to show up, but the prev. next will not.

I wonder what I'm doing wrong.

8 | Matt

May 25th, 2004 at 1:10 am

Avatar

For the main link you can put <?php bloginfo('url'); ?>

9 | bran

May 25th, 2004 at 2:01 am

Avatar

Jennifer–thou art the Scripty-est Goddess i know of. thank you for lighting the way toward next/previous link bliss in WP.

10 | Clay

May 25th, 2004 at 1:23 pm

Avatar

My code is almost the same, but I didn't want the pipe ("|") to show unless there was a link. I didn't want this: "| Home | Next Article". I wanted this: "Home | Next Article". So here's my code (notice, I don't have an intro like "Next article", just the title of the article itself):

<?php if ($single) { ?>
<div class="navigation"><?php previous_post('% |',",'yes') ?> <a href="/">Home</a> <?php next_post('| %',",'yes') ?></div>
<?php } ?>

11 | Happy

May 25th, 2004 at 4:56 pm

Avatar

Jennifer, thank you for coming up with these great WP tips!

12 | Charlene

May 26th, 2004 at 5:29 pm

Avatar

Jennifer, that is too awesome. Thank you. I'm going to play with this soon.

13 | Kathy K

May 26th, 2004 at 6:08 pm

Avatar

I wanted a link to next/previous 15 posts on my index page, so I used something exactly opposite this…

<?php if (!$single) { ?><div class="pagenav"><?php previous_posts_link('&laquo; Previous 15 posts ::') ?> <a href="index.php">Main</a> <?php next_posts_link(':: Next 15 posts &raquo;') ?> <?php } ?>

I used 'if not single' to keep a lonely 'Main' link from showing at the bottom of my individual pages. Thought someone might find the code handy so I posted it here. (You have to set to x "posts paged" in your WP options/Reading for this to work.)

14 | Kathy K

May 26th, 2004 at 6:11 pm

Avatar

Oops. There should be an ending </div> right before the <?php } ?>

15 | SilverBlue

May 27th, 2004 at 1:54 pm

Avatar

What can I say? You're the greatest!

16 | Sally

May 31st, 2004 at 12:43 am

Avatar

Is there a way to have wp display "plain" previous/next links, without post titles?

i.e. you would have: "previous | next" rather than "previous post title | next post title".

17 | Mark J

May 31st, 2004 at 5:45 am

Avatar

I wanted that on my site too Sally. Here's what'll do it:

<?php if($single){
previous_post('%','« Previous Entry','no','no',1,"); ?> |
<a href="<?php bloginfo('url'); ?>">Main</a> |
<?php next_post('%','Next Entry »','no','no',1,");
} ?>

18 | Sally

May 31st, 2004 at 6:01 pm

Avatar

Wonderful, Mark — thanks for your help!

19 | Code Novice

May 31st, 2004 at 5:35 pm

Avatar

WordPress Bookmarks
A slew of WP bookmarks, plugins, etc. as seen on Scriptygoddess:

20 | identity

June 2nd, 2004 at 8:28 am

Avatar

more MT vs. WP
jill/txt » problems switching from Movable Type to WordPress My comment is here because I need some of this later, and possibly it might be of use for you too? I find some of your findings (pun not intended) strange….

21 | U Rappin' GOO? » WordPress ME¤Ë°Ü¹Ô

August 17th, 2004 at 8:26 am

Avatar

[…] ¬Â¿¤¤¥Ú¡¼¥¸¤òʬ³ä¤·¤Æɽ¼¨¥×¥é¥°¥¤¥ó Recently Commented Posts ¡Ä ºÇ¶á¤Î¥³¥á¥ó¥È¥×¥é¥°¥¤¥ó ¡ÖÁ°¤Î¥¨¥ó¥È¥ê¡¼ | ¥È¥Ã¥× | ¼¡¤Î¥¨¥ó¥È¥ê¡¼¡× ¡ […]

22 | Colorful typhoon » Previous Post | Home | Next Post” links

August 23rd, 2004 at 8:39 pm

Avatar

[…] ¹ãƒˆãƒŠãƒ“(というのかな?)をつけてみました。参考先はお馴染みのscriptygoddessさんです。各記事のタ゠[…]

23 | One Woman, Five Cats and a Crowbar » More Navigation Than You Can Shake a Stick At!

August 26th, 2004 at 6:39 pm

Avatar

[…] to the main page, and b) be able to surf through a series of single posts. First, I found this thread. That let me add previous | main […]

24 | Greg

June 20th, 2004 at 12:55 pm

Avatar

Was anyone able to get the exclude categories function to work with the previous/next links? I've tried everything and all posts keep showing up. I basically only want one categories worth of posts to show up in my previous/next links. Ugh.

25 | Sassy

July 3rd, 2004 at 12:32 pm

Avatar

Excellent! Works great!

26 | Mama Write

July 7th, 2004 at 8:01 pm

Avatar

Various WordPress Links
Rather than ping ScriptyGoddess multiple times and clog my sideblog with even more WordPress links, I decided to plop 'em all here. I'm going to give WordPress a try again on my course website, since there are various hacks that…

27 | Kara

July 16th, 2004 at 6:45 am

Avatar

Would it be possible to have 'next' and 'previous' links for categories?

28 | Tod

September 3rd, 2004 at 2:25 pm

Avatar

How would I go about making it appear on the index page? I run a daily blog, but would like to use this to add navigation to go to the previous day from the front page. Works great in the archives.
Thank you.

29 | Tod

September 3rd, 2004 at 2:29 pm

Avatar

Sorry, wrong plugin. I was referring to your previous/next archive date plugin.

30 | igor

September 24th, 2004 at 3:02 pm

Avatar

What is the function: "php next_post"?

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements