WordPress.org

Support

Support » Plugins and Hacks » Smarter Navigation » [Plugin: Smarter Navigation] How can I change Smarter-Navigation plugin to navigate by menu order?

[Plugin: Smarter Navigation] How can I change Smarter-Navigation plugin to navigate by menu order?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author scribu

    @scribu

    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.

    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.

    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;
    }

    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];
    	}
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Smarter Navigation] How can I change Smarter-Navigation plugin to navigate by menu order?’ is closed to new replies.
Skip to toolbar