May 02, 2018
Below is an example of the_post_navigation customized to include an image and custom text for previous and next.
Add this snippet to your functions file, link to your images, and then call it where you would like the_post_navigation to appear.
function themename_the_post_navigation( $args = array() ) {
$args = wp_parse_args( $args, array(
'prev_text' => '<img src="'.get_bloginfo('stylesheet_directory').'/img/blue-arrow-prev.png" class="arrow" /> Older',
'next_text' => 'Newer <img src="'.get_bloginfo('stylesheet_directory').'/img/blue-arrow.png" class="arrow" />',
'in_same_term' => false,
'excluded_terms' => '',
'taxonomy' => 'category',
'screen_reader_text' => __( 'Post navigation' ),
) );
$navigation = '';
$previous = get_previous_post_link(
'<div class="nav-previous">%link</div>',
$args['prev_text'],
$args['in_same_term'],
$args['excluded_terms'],
$args['taxonomy']
);
$next = get_next_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'] );
}
return $navigation;
}
Place in theme:
echo themename_the_post_navigation();
Example appearance:
Sourced here.
cool! thanks 🙂
HI, can i exclude some pages from pagination. I add this code to a list of child pages? and dont want to show links to their parent pages. Thanks in a advance)
Hey, this snippet is geared more towards Post pagination, but you can still control what is seen in the paging by updating ‘taxonomy’ => ‘category’ to a specific taxonomy in order to stay within a certain category.
I think this is more what you’re looking for. It will allow you to choose the Post Type (to Pages), and you can add post_parent to get_posts() to stay within the child items.
Let me know if that helps!
Cool! Thanks for the code. It’s very usefull and works totally fine
Glad you found it helpful! 🙂