0

I am using a custom query on a page to display single posts from a specific category, one post per page. Here is my current query:

$results = new WP_Query( array(
    'post_type' => 'post',
    'posts_per_page' => 1,
    'paged' => get_query_var( 'paged' ),
    'cat' => 6
    ) );

Right now I have pagination setup that displays < Previous and Next > links. I want to replace those links with the title of the next and previous. Is this possible to do since technically this does not live under a "Single" post but rather more of an archive inside of a page? I have tried next_post_link(), etc. but since I am only retrieving one post per page, this doesn't work.

Ideas?

1 Answer 1

0

This doesn't seem terribly efficient but you could just look up the next/prev posts in the loop used to display the post then output the post titles in the nav calls.

// loop
if ( have_posts() ) : while ( have_posts() ) : the_post();

  // ... post display

  // next & prev post data
  $older = get_previous_post();
  $newer = get_next_post();
endwhile; endif;

// pagination
next_posts_link( $older->post_name );
previous_posts_link( $newer->post_name );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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