“Previous Post | Home | Next Post” links in wordpress
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.
May 23rd, 2004 at 3:12 pm
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.
May 23rd, 2004 at 4:40 pm
you are brilliant. thank you!!
May 23rd, 2004 at 5:01 pm
KO - I would think so… I see a plugin in the future
(But I can’t guarantee when…)
May 23rd, 2004 at 5:03 pm
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=”)
May 23rd, 2004 at 5:06 pm
See this page for previous post
and this page for next post
It’s already in there - no plugin needed. Yee ha!
May 23rd, 2004 at 5:44 pm
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?
May 25th, 2004 at 12:18 am
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.
May 25th, 2004 at 1:10 am
For the main link you can put <?php bloginfo(’url’); ?>
May 25th, 2004 at 2:01 am
Jennifer–thou art the Scripty-est Goddess i know of. thank you for lighting the way toward next/previous link bliss in WP.
May 25th, 2004 at 1:23 pm
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 } ?>
May 25th, 2004 at 4:56 pm
Jennifer, thank you for coming up with these great WP tips!
May 26th, 2004 at 5:29 pm
Jennifer, that is too awesome. Thank you. I’m going to play with this soon.
May 26th, 2004 at 6:08 pm
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(’« Previous 15 posts ::’) ?> <a href=”index.php”>Main</a> <?php next_posts_link(’:: Next 15 posts »’) ?> <?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.)
May 26th, 2004 at 6:11 pm
Oops. There should be an ending </div> right before the <?php } ?>
May 27th, 2004 at 1:54 pm
What can I say? You’re the greatest!
May 31st, 2004 at 12:43 am
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”.
May 31st, 2004 at 5:45 am
I wanted that on my site too Sally. Here’s what’ll do it:
May 31st, 2004 at 5:35 pm
A slew of WP bookmarks, plugins, etc. as seen on Scriptygoddess:
May 31st, 2004 at 6:01 pm
Wonderful, Mark — thanks for your help!
June 2nd, 2004 at 8:28 am
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….
June 20th, 2004 at 12:55 pm
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.
July 3rd, 2004 at 12:32 pm
Excellent! Works great!
July 7th, 2004 at 8:01 pm
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…
July 16th, 2004 at 6:45 am
Would it be possible to have ‘next’ and ‘previous’ links for categories?
August 17th, 2004 at 8:26 am
August 23rd, 2004 at 8:39 pm
August 26th, 2004 at 6:39 pm
September 3rd, 2004 at 2:25 pm
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.
September 3rd, 2004 at 2:29 pm
Sorry, wrong plugin. I was referring to your previous/next archive date plugin.
September 24th, 2004 at 3:02 pm
What is the function: “php next_post”?