Created
April 7, 2025 07:31
-
-
Save thecodepoetry/4c8b42e1c3dbcc166968c816bb02c465 to your computer and use it in GitHub Desktop.
Album Next prev in same category
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 = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"><path class="st0" d="M11.4,1.6c0.2,0.2,0.2,0.5,0,0.7c0,0,0,0,0,0L5.7,8l5.6,5.6c0.2,0.2,0.2,0.5,0,0.7s-0.5,0.2-0.7,0l-6-6c-0.2-0.2-0.2-0.5,0-0.7c0,0,0,0,0,0l6-6C10.8,1.5,11.2,1.5,11.4,1.6C11.4,1.6,11.4,1.6,11.4,1.6z"/></svg>' . | |
'<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 ( 'dt_gallery' == get_post_type() ) { | |
$prev_link = get_previous_post_link( | |
'%link', | |
$prev_text, | |
true, | |
$args['excluded_terms'], | |
'dt_gallery_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( '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"><path d="M1,2c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1H2C1.4,5,1,4.6,1,4V2z M6,2c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1H7C6.4,5,6,4.6,6,4V2z M11,2c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1h-2c-0.6,0-1-0.4-1-1V2z M1,7c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1H2c-0.6,0-1-0.4-1-1V7z M6,7c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1H7c-0.6,0-1-0.4-1-1V7z M11,7c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1h-2c-0.6,0-1-0.4-1-1V7z M1,12c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1H2c-0.6,0-1-0.4-1-1V12z M6,12c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1H7c-0.6,0-1-0.4-1-1V12z M11,12c0-0.6,0.4-1,1-1h2c0.6,0,1,0.4,1,1v2c0,0.6-0.4,1-1,1h-2c-0.6,0-1-0.4-1-1V12z"/></svg>' ); | |
} | |
if ( $config->get( 'post.navigation.arrows.enabled' ) ) { | |
$next_text = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve"><path class="st0" d="M4.6,1.6c0.2-0.2,0.5-0.2,0.7,0c0,0,0,0,0,0l6,6c0.2,0.2,0.2,0.5,0,0.7c0,0,0,0,0,0l-6,6c-0.2,0.2-0.5,0.2-0.7,0s-0.2-0.5,0-0.7L10.3,8L4.6,2.4C4.5,2.2,4.5,1.8,4.6,1.6C4.6,1.6,4.6,1.6,4.6,1.6z"/></svg>' . | |
'<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 ( 'dt_gallery' == get_post_type() ) { | |
$next_link = get_next_post_link( | |
'%link', | |
$next_text, | |
true, | |
$args['excluded_terms'], | |
'dt_gallery_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 ) { | |
$nav_class = array( | |
'navigation', | |
'post-navigation', | |
); | |
if ( ! $config->get( 'post.navigation.arrows.enabled' ) ) { | |
$nav_class[] = 'disabled-post-navigation'; | |
} | |
$output = '<nav class="' . esc_attr( implode( ' ', $nav_class ) ) . '" 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