WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an index.php page that is only displaying 1 post at a time with a query.

(found this code online, but it does work)

$page  = (get_query_var('paged')) ? get_query_var('paged') : 1;

// if we are paging
if ($page == 1) {
} else {
    $numposts  = get_option('posts_per_page');

// work out offset
$offset = (($page -1) * $numposts); // i.e. page 2 - 1 = 1 * 10 (10 for the number of posts)



This correctly shows one post per page, and it displays the navigation on the bottom of my template when I put a <?php posts_nav_link(); ?> in there.

Is there anyway to change the "Next Page" and "Previous Page" links to be the titles of the posts themselves?

share|improve this question

If I understood well to your question this should work.


global $paged;

if($paged > 1) {

$previous_post = get_adjacent_post(false, '', false) ;

$prev_post_title = get_the_title($previous_post->ID);

} else {

$prev_post_title = null;


$next_post = get_adjacent_post(true, '', true) ;

$next_post_title = get_the_title($next_post->ID);

posts_nav_link('&bull;', $prev_post_title, $next_post_title);


Just copy and paste in someplace of your index.php.

share|improve this answer
For some reason this is getting the adjacent Pages for me? I have a "Blog" page that is using a blog.php template. – dmackerman Nov 23 '11 at 15:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.