Created
April 7, 2020 13:06
-
-
Save thecodepoetry/8f7f35148ca69885d3026fbf73b9d45f to your computer and use it in GitHub Desktop.
Next prev throug same category for post and portfolio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function presscore_new_post_navigation( $args = array() ) { | |
if ( ! in_the_loop() ) { | |
return ''; | |
} | |
$defaults = array( | |
'prev_src_text' => __( 'Previous post:', 'the7mk2' ), | |
'next_src_text' => __( 'Next post:', 'the7mk2' ), | |
'in_same_term' => false, | |
'excluded_terms' => '', | |
'taxonomy' => 'category', | |
'screen_reader_text' => __( 'Post navigation', 'the7mk2' ), | |
); | |
$args = wp_parse_args( $args, $defaults ); | |
$config = presscore_config(); | |
$output = ''; | |
if ( $config->get( 'post.navigation.arrows.enabled' ) ) { | |
$prev_text = '<i class="icomoon-the7-font-the7-arrow-29-3" aria-hidden="true"></i>' . | |
'<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'the7mk2' ) . '</span>' . | |
'<span class="screen-reader-text">' . esc_html( $args['prev_src_text'] ) . '</span>' . | |
'<span class="post-title h4-size">%title</span>'; | |
// We use opposite order. | |
if ( 'post' == get_post_type() ) { | |
$prev_link = get_previous_post_link( | |
'%link', | |
$prev_text, | |
true, | |
$args['excluded_terms'], | |
$args['taxonomy'] | |
); | |
} | |
elseif ( 'dt_portfolio' == get_post_type() ) { | |
$prev_link = get_previous_post_link( | |
'%link', | |
$prev_text, | |
true, | |
$args['excluded_terms'], | |
'dt_portfolio_category' | |
); | |
} | |
else { | |
$prev_link = get_previous_post_link( | |
'%link', | |
$prev_text, | |
$args['in_same_term'], | |
$args['excluded_terms'], | |
$args['taxonomy'] | |
); | |
} | |
$prev_link = str_replace( '<a', '<a class="nav-previous"', $prev_link ); | |
if ( ! $prev_link ) { | |
$prev_link = '<span class="nav-previous disabled"></span>'; | |
} | |
$output .= $prev_link; | |
} | |
if ( $config->get( 'post.navigation.back_button.enabled' ) ) { | |
$output .= presscore_get_post_back_link( '<i class="dt-icon-the7-misc-006-1" aria-hidden="true"></i>' ); | |
} | |
if ( $config->get( 'post.navigation.arrows.enabled' ) ) { | |
$next_text = '<i class="icomoon-the7-font-the7-arrow-29-2" aria-hidden="true"></i>' . | |
'<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'the7mk2' ) . '</span>' . | |
'<span class="screen-reader-text">' . esc_html( $args['next_src_text'] ) . '</span>' . | |
'<span class="post-title h4-size">%title</span>'; | |
// We use opposite order. | |
if ( 'post' == get_post_type() ) { | |
$next_link = get_next_post_link( | |
'%link', | |
$next_text, | |
true, | |
$args['excluded_terms'], | |
$args['taxonomy'] | |
); | |
} | |
elseif ( 'dt_portfolio' == get_post_type() ) { | |
$next_link = get_next_post_link( | |
'%link', | |
$next_text, | |
true, | |
$args['excluded_terms'], | |
'dt_portfolio_category' | |
); | |
} | |
else { | |
$next_link = get_next_post_link( | |
'%link', | |
$next_text, | |
$args['in_same_term'], | |
$args['excluded_terms'], | |
$args['taxonomy'] | |
); | |
} | |
$next_link = str_replace( '<a', '<a class="nav-next"', $next_link ); | |
if ( ! $next_link ) { | |
$next_link = '<span class="nav-next disabled"></span>'; | |
} | |
$output .= $next_link; | |
} | |
if ( $output ) { | |
$output = '<nav class="navigation post-navigation" role="navigation"><h2 class="screen-reader-text">' . esc_html( $args['screen_reader_text'] ) . '</h2><div class="nav-links">' . $output . '</div></nav>'; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this code in your child theme functions.php to navigate to Portfolio Next Prev button only through same category.