I don’t quite understand what you’re asking, maybe you could explain a bit more. What do you mean by “Previous Button”? You mentioned the code above so I assume you’re talking about the Read Post button on the Posts Page/Blog Page.
Or are you talking about the next/previous post buttons under each Single post? If that is what you mean and you want the Next/Previous buttons to link to posts that are of the same category then add this on your child-theme’s functions.php:
function custom_single_post_nav() {
$prev_post = get_previous_post(true);
$next_post = get_next_post(true);
$post_nav_single = '';
if ( !empty($prev_post) )
$post_nav_single .= '<div class="link-prev"><a href="' . get_permalink( $prev_post->ID ) . '" title="' . esc_attr( $prev_post->post_title ) . '">' . __('← Previous Post', 'frontier') . '</a></div>';
if ( !empty($next_post) )
$post_nav_single .= '<div class="link-next"><a href="' . get_permalink( $next_post->ID ) . '" title="' . esc_attr( $next_post->post_title ) . '">' . __('Next Post →', 'frontier') . '</a></div>';
return $post_nav_single;
}
add_filter( 'frontier_post_nav_single', 'custom_single_post_nav' );
Hi ron
Thanks for your reply. The code i paste works fine that’s exactly what i wanted. I just want to add the relevant code to make it appears only on the post in the same category.
in this link
The right link connects to a post in a different category.
function custom_single_post_nav( $post_nav_single ) {
if ( is_single('328') ) {
$prev_post = get_previous_post(true);
$next_post = get_next_post(true);
$post_nav_single = '';
if ( !empty($prev_post) )
$post_nav_single .= '<div class="link-prev"><a href="' . get_permalink( $prev_post->ID ) . '" title="' . esc_attr( $prev_post->post_title ) . '">' . __('← Previous Post', 'frontier') . '</a></div>';
if ( !empty($next_post) )
$post_nav_single .= '<div class="link-next"><a href="' . get_permalink( $next_post->ID ) . '" title="' . esc_attr( $next_post->post_title ) . '">' . __('Next Post →', 'frontier') . '</a></div>';
}
return $post_nav_single;
}
add_filter( 'frontier_post_nav_single', 'custom_single_post_nav' );
328 is the Post ID.