Skip to content

Instantly share code, notes, and snippets.

@saltnpixels
Created April 14, 2020 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saltnpixels/1e3dbb1c53395c3b3fa6017f17f7810b to your computer and use it in GitHub Desktop.
Save saltnpixels/1e3dbb1c53395c3b3fa6017f17f7810b to your computer and use it in GitHub Desktop.
WP Reverse Post Navigation
//found this somewhere on the internet. Reverses the navigation.
//works well with the Post Type Order navigation here https://wordpress.org/plugins/simple-custom-post-order/
//shows the prev and next post in reverse which helps when ordering posts not by date
function the_reverse_post_navigation( $args = array() ) {
$args = wp_parse_args( $args, array(
'prev_text' => '%title',
'next_text' => '%title',
'in_same_term' => false,
'excluded_terms' => '',
'taxonomy' => 'category',
'screen_reader_text' => __( 'Post navigation' ),
) );
$navigation = '';
$previous = get_next_post_link(
'<div class="nav-previous">%link</div>',
$args['prev_text'],
$args['in_same_term'],
$args['excluded_terms'],
$args['taxonomy']
);
$next = get_previous_post_link(
'<div class="nav-next">%link</div>',
$args['next_text'],
$args['in_same_term'],
$args['excluded_terms'],
$args['taxonomy']
);
// Only add markup if there's somewhere to navigate to.
if ( $previous || $next ) {
$navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] );
}
echo $navigation;
}
//how to use
the_reverse_post_navigation( array(
'prev_text' => __( 'Previous Post', 'ignitionpress' ),
'next_text' => __( 'Up Next', 'ignitionpress' ),
) );
@saltnpixels
Copy link
Author

You may also want to set your query (front end) to use:
orderby = menu_order
order = ASC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment