get_next_posts_link() returns no result despite available posts

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x