Making WordPress.org


Ignore:
Timestamp:
04/17/2018 07:38:47 AM (7 years ago)
Author:
pento
Message:

Gutenberg Theme: Ensure previous/next page links are ordered by menu_order, rather than post_date.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php

    r6323 r7118  
    141141add_action( 'wp_enqueue_scripts', 'gutenbergtheme_scripts' );
    142142
     143function gutenbergtheme_adjacent_post_order( $order_by, $post, $order ) {
     144    if ( 'handbook' !== $post->post_type ) {
     145        return $order_by;
     146    }
     147
     148    return "ORDER BY p.menu_order $order LIMIT 1";
     149}
     150add_filter( 'get_previous_post_sort', 'gutenbergtheme_adjacent_post_order', 10, 3 );
     151add_filter( 'get_next_post_sort', 'gutenbergtheme_adjacent_post_order', 10, 3 );
     152
     153function gutenbergtheme_previous_post_where( $where, $in_same_term, $excluded_term, $taxonomy, $post ) {
     154    if ( 'handbook' !== $post->post_type ) {
     155        return $order_by;
     156    }
     157
     158    return "WHERE p.post_type='handbook' AND p.post_status='publish' AND p.menu_order < {$post->menu_order}";
     159}
     160add_filter( 'get_previous_post_where', 'gutenbergtheme_previous_post_where', 10, 5 );
     161
     162function gutenbergtheme_next_post_where( $where, $in_same_term, $excluded_term, $taxonomy, $post ) {
     163    if ( 'handbook' !== $post->post_type ) {
     164        return $order_by;
     165    }
     166
     167    return "WHERE p.post_type='handbook' AND p.post_status='publish' AND p.menu_order > {$post->menu_order}";
     168}
     169add_filter( 'get_next_post_where', 'gutenbergtheme_next_post_where', 10, 5 );
     170
    143171/**
    144172 * Implement the Custom Header feature.
Note: See TracChangeset for help on using the changeset viewer.