Previous/next page order

Hello,

I put the code below in the child functions.php but I don’t understand the displaying order.
Ideally, I would like an order with date, in the same pages of a parent page. Possible?
Thanks so much

add_action( 'the_content', 'add_next_post_item_link' );

function add_next_post_item_link ( $content ) {
    if ( is_singular('page') ) {
	    $next_name = '<span>Page suivante</span><br/> ' . get_the_title( get_next_post()->ID );
	    $prev_name = '<span>Page précédente</span><br/> ' . get_the_title( get_previous_post()->ID );
	    $next_link = get_next_post() ? '<a class="prev" href="' . get_permalink( get_next_post()->ID ) . '">' . $prev_name . '</a>' : '';
	    $prev_link = get_previous_post() ? '<a class="next" href="' . get_permalink( get_previous_post()->ID ) . '">' . $next_name . '</a>' : '';
	    $posts = '<div class="wp-post-navigation-next">'.$next_link.$prev_link.'</div>';
	    return $content . $posts;
    } else {
	    return $content;
    }
}

Hi Cedric,

Thanks for reaching out.

The next and previous features are usually for a post with category taxonomy, as by default.


With that, it could be by order of date for the page, but I’m not really sure since it’s a Wordpress feature. Hence, if you’re going to use it other than post, you’ll have to do some customization that will allow it, example https://stackoverflow.com/questions/10376891/make-get-adjacent-post-work-across-custom-post-types

It’s a Wordpress function and we can’t cover or provide customization here in the forum. What I provided is just a reference. The function get_next_post() calls get_adjacent_post(), and they are connected. You can only apply your own through customization.

Thanks!

Thanks for your answer

You are most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.