# Can posts_nav_link show post titles?

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) {
query_posts('order=DESC&posts_per_page=1&paged=$page'); } 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) query_posts("&order=DESC&offset=$offset&paged=$page&showposts=$numposts");


}

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?

If I understood well to your question this should work.

<?php

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.

• 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