0

I am developing a custom theme based on the Genesis framework. I want to display a 'previous post | next post' navigation below any article in the single post view. However, neither get_next_posts_link() nor get_previous_posts_link() return any value. All output I can see is

|

Of course, there are adjacent posts available.

My code looks something like this

single.php

<?php
  
  function myslug_render_post_navigation(){
    echo get_next_posts_link( __( 'Previous post' ) ) . ' | ' . get_previous_posts_link( __( 'Next post' ) );
  }
  add_action( 'genesis_after_entry', 'myslug_render_post_navigation' );
  
  genesis();

Can anyone point me in the right direction?

1 Answer 1

1

get_next_posts_link() and get_previous_posts_link() are for linking between pages of a paginated post archive.

For navigation between individual posts you want get_next_post_link() and get_previous_post_link(). Note the singular "post".

function myslug_render_post_navigation(){
    echo get_next_post_link( __( 'Previous post' ) ) . ' | ' . get_previous_post_link( __( 'Next post' ) );
}
add_action( 'genesis_after_entry', 'myslug_render_post_navigation' );

genesis();

I've noticed that you've got get_next_posts_link() and get_previous_posts_link() backwards relative to their labels, but I haven't changed this in my example in case that was intentional.

1
  • That absolutely works fine, thnx!
    – Bunjip
    Jul 14, 2020 at 6:45

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.