Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top