WordPress Menu Order Sort for Adjacent Previous - Next Single Post Navigation - https://amethystwebsitedesign.com/wordpress-menu-order-sort-for-adjacent-previous-next-single-post-navigation
<?php | |
// Do NOT add the line above when you copy. | |
/** Add previous/next post navigation on book posts. | |
* http://snipplr.com/view/74493/adjacent-post-by-alphabetical-order-in-wordpress/ | |
* /wp-includes/link-template.php | |
* line 1608 | |
* $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms ); | |
* line 1620 | |
* $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); | |
*/ | |
add_action( 'genesis_entry_footer', 'amethyst_book_post_nav', 16 ); | |
function amethyst_book_post_nav() { | |
if ( is_singular( 'book-post' ) ) { | |
global $post, $wpdb; | |
// Section 1. | |
function filter_next_post_sort( $sort ) { | |
$sort = 'ORDER BY p.menu_order ASC LIMIT 1'; | |
return $sort; | |
} | |
function filter_next_post_where( $where ) { | |
global $post, $wpdb; | |
$where = $wpdb->prepare( "WHERE p.menu_order > '%s' AND p.post_type = 'book-post' AND p.post_status = 'publish'",$post->menu_order ); | |
return $where; | |
} | |
function filter_previous_post_sort( $sort ) { | |
$sort = 'ORDER BY p.menu_order DESC LIMIT 1'; | |
return $sort; | |
} | |
function filter_previous_post_where($where) { | |
global $post, $wpdb; | |
$where = $wpdb->prepare( "WHERE p.menu_order < '%s' AND p.post_type = 'book-post' AND p.post_status = 'publish'",$post->menu_order ); | |
return $where; | |
} | |
add_filter( 'get_next_post_sort', 'filter_next_post_sort' ); | |
add_filter( 'get_next_post_where', 'filter_next_post_where' ); | |
add_filter( 'get_previous_post_sort', 'filter_previous_post_sort' ); | |
add_filter( 'get_previous_post_where', 'filter_previous_post_where' ); | |
// Section 2. | |
$previous_post = get_previous_post(); | |
$next_post = get_next_post(); | |
echo '<div class="adjacent-entry-pagination pagination">'; | |
if ( $previous_post ) { | |
echo '<div class="pagination-previous"><a href="' .get_permalink( $previous_post->ID ). '"><span>Previous Chapter</span>' .$previous_post->post_title. '</a></div>'; | |
} else { | |
echo '<div class="pagination-previous"><a href="' .get_post_type_archive_link( 'book-post' ). '"><span>Chapter Summaries</span>Book Title</a></div>'; | |
} | |
if ( $next_post ) { | |
echo '<div class="pagination-next"><a href="' .get_permalink( $next_post->ID ). '"><span>Next Chapter</span>' .$next_post->post_title. '</a></div>'; | |
} else { | |
echo '<div class="pagination-next"><a href="' .get_post_type_archive_link( 'book-post' ). '"><span>Chapter Summaries</span>Book Title</a></div>'; | |
} | |
echo '</div>'; | |
} | |
} |
/* Adjacent Pagination | |
--------------------------------------------- */ | |
.pagination { | |
clear: both; | |
margin: 30px 0 0; | |
} | |
.adjacent-entry-pagination { | |
border-top: 1px solid #999; | |
border-bottom: 1px solid #999; | |
font-family: Lora, Georgia, serif; | |
margin: 60px 0 0; | |
} | |
.adjacent-entry-pagination .pagination-previous, | |
.adjacent-entry-pagination .pagination-next { | |
display: block; | |
float: left; | |
padding: 15px 0; | |
text-align: center; | |
width: 50%; | |
} | |
.adjacent-entry-pagination .pagination-previous { | |
border-right: 1px solid #999; | |
} | |
.adjacent-entry-pagination .pagination-next { | |
float: right; | |
} | |
.adjacent-entry-pagination .pagination-previous a, | |
.adjacent-entry-pagination .pagination-next a { | |
color: #454545; | |
text-decoration: none; | |
} | |
.adjacent-entry-pagination .pagination-previous a:hover, | |
.adjacent-entry-pagination .pagination-previous a:focus, | |
.adjacent-entry-pagination .pagination-next a:hover, | |
.adjacent-entry-pagination .pagination-next a:focus { | |
color: #4251ce; | |
text-decoration: underline; | |
} | |
.adjacent-entry-pagination .pagination-previous span, | |
.adjacent-entry-pagination .pagination-next span { | |
display: block; | |
font-style: italic; | |
} | |
.adjacent-entry-pagination .pagination-previous span::before, | |
.adjacent-entry-pagination .pagination-next span::after, | |
.archive-pagination .pagination-previous a::before, | |
.archive-pagination .pagination-next a::after { | |
content: "\f341"; | |
display: inline-block; | |
-webkit-font-smoothing: antialiased; | |
font: normal 18px/1 'dashicons'; | |
padding: 0 3px 3px 0; | |
vertical-align: middle; | |
} | |
.adjacent-entry-pagination .pagination-next span::after { | |
content: "\f345"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment