Smarter Navigation
How can I change Smarter-Navigation plugin to navigate by menu order? (5 posts)

  1. jshultz
    Posted 4 years ago #

    I'm using the wordpress plugin Smarter-Navigation to navigate categories. The problem I'm having is this: The posts under the category are sorted by menu-order. However, using Smarter-Navigation, the previous/next links are generated by post date. I need them to be generated by menu-order. If you look at: http://www.goshwara.com/wordpress/index.php/category/jewelry/pendants/ you can see how the order of the posts is different when you look at a particular post. I'm hoping this makes sense?


  2. scribu
    Plugin Author

    Posted 4 years ago #

    It depends how you modify the order. If you're using query_posts() or new WP_Query directly in the template file, it won't work. You need to use one of 'parse_query' or 'pre_get_posts' actions. Google it.

  3. jshultz
    Posted 4 years ago #

    The name of the column that is storing the menu order is: menu_order. So, the posts are created and then using drag/drop within the wp admin you can set the order in how they will appear in the category. So, the posts are appearing the category based on how they are sorted in wp admin.

    So what is happening is the posts are ordered in wp-admin. Simple Page Ordering is displaying the posts in order based upon the order of the posts using the field menu_order in the wp_post table.

  4. jshultz
    Posted 4 years ago #

    here's the db query it's using to generate the posts:

    static function posts_clauses( $bits, $wp_query ) {
    global $wpdb;

    $direction = $wp_query->get( 'smarter_navigation' );

    if ( !$direction )
    return $bits;

    $orderby = preg_split( '|\s+|', $bits['orderby'] );
    $orderby = reset( $orderby );

    $field = explode( '.', $orderby );
    $field = end( $field );

    $post = get_queried_object();

    if ( isset( $post->$field ) ) {
    $bits['where'] .= $wpdb->prepare( " AND $orderby $direction %s ", $post->$field );
    $bits['limits'] = 'LIMIT 1';
    } else {
    $bits['where'] = ' AND 1 = 0';

    return $bits;

  5. supertomate
    Posted 4 years ago #

    Hi jshultz,

    Ardesign gaves a solution in this reply : http://wordpress.org/support/topic/plugin-smarter-navigation-switch-to-order-by-menu_order?replies=4

    simply modify the get_adjacent_id function by adding 'orderby' => 'menu_order' in the $args

    static function get_adjacent_id( $previous = false ) {
    		if ( !isset( self::$data['query'] ) )
    			return -1;
    		$previous = (bool) $previous;
    		if ( !isset( self::$cache[$previous] ) ) {
    			$args = array_merge( self::$data['query'], array(
    				'smarter_navigation' => $previous ? '<' : '>',
    				'order' => $previous ? 'DESC' : 'ASC',
    				'ignore_sticky_posts' => true,
    				'nopaging' => true,
    				'orderby' => 'menu_order'
    			) );
    			$q = new WP_Query( $args );
    			self::$cache[$previous] = empty( $q->posts ) ? 0 : $q->posts[0]->ID;
    		return self::$cache[$previous];

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Smarter Navigation
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic