Support » Fixing WordPress » Custom Post Display Page : Sort by Menu order

  • I have been trying to get this to work for a while and have given up on my own. I have custom page templates that are pulling post types. I want them to order the posts on the page by menu_order(?) but I get seem to get the code to work. This piece of codes puts them on the site, but the order is display by creation.

    <?php $wp_query->query("post_type=howWeWork&". $catinclude ."&paged=".$paged.'&showposts=12'); ?>

    Please help.

    Thank you all.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Id use something like

    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    
    $args = array(
    	'post_type' => 'howWeWork',
    	'posts_per_page' => 12,
    	'orderby'=> 'menu_order,
    	'order'=>'ASC',
    	'paged' => $paged
    );
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
            echo '<ul>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<li>' . get_the_title() . '</li>';
    	}
            echo '</ul>';
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    See more here: http://codex.wordpress.org/Class_Reference/WP_Query

    Thank you for looking domokun, but that made my page show up blank. I even tried updated the variable $the_query to my $wp_query, but that didn’t work either.

    <?php

    /**

    * Template Name: How We Work 4 columns

    */

    get_header(); ?>

    <div id=”content” class=”grid_12″>

    <?php include_once (TEMPLATEPATH . ‘/title.php’);?>

    <?php global $more; $more = 0;?>

    <?php $values = get_post_custom_values(“category-include”); $cat=$values[0]; ?>

    <?php $catinclude = ‘howWeWork_category=’. $cat ;?>
    <?php $temp = $wp_query;

    $wp_query= null;

    $wp_query = new WP_Query(); ?>

    <?php $wp_query->query(“post_type=howWeWork&”. $catinclude .”&paged=”.$paged.’&showposts=12′); ?>

    <?php if ( ! have_posts() ) : ?>

    <div id=”post-0″ class=”post error404 not-found”>

    <h1 class=”entry-title”><?php _e( ‘Not Found’, ‘theme1438’ ); ?></h1>

    <div class=”entry-content”>

    <p><?php _e( ‘Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.’, ‘theme1438’ ); ?></p>

    <?php get_search_form(); ?>

    </div><!– .entry-content –>

    </div><!– #post-0 –>

    <?php endif; ?>

    <div id=”gallery” class=”four_columns”>

    <ul class=”portfolio”>

    <?php

    $i=1;

    if ( have_posts() ) while ( have_posts() ) : the_post();

    if(($i%4) == 0){ $addclass = “nomargin”; }

    ?>

    <?php

    $custom = get_post_custom($post->ID);

    $lightbox = $custom[“lightbox-url”][0];

    ?>

    <li class=”<?php echo $addclass; ?>”>

    <?php if($lightbox!=””){ ?>

    <span class=”image-border”>” rel=”prettyPhoto[gallery]” title=”<?php the_title();?>”><?php the_post_thumbnail( ‘howWeWork-post-thumbnail-small’ ); ?><span class=”zoom-icon”></span></span>

    <?php }else{ ?>

    <span class=”image-border”>” title=”<?php _e(‘Permanent Link to’, ‘theme1438’);?> <?php the_title_attribute(); ?>” ><?php the_post_thumbnail( ‘howWeWork-post-thumbnail-small’ ); ?></span>

    <?php } ?>

    <div class=”folio-desc”>

    <h4>“><?php $title = the_title(”,”,FALSE); echo substr($title, 0, 40); ?></h4>

    <p class=”excerpt”><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,16);?></p>

    “>Read more →

    </div>

    <?php $i++; $addclass = “”; endwhile; ?>

    <div class=”clear”></div>

    </div>

    <?php if(function_exists(‘wp_pagenavi’)) : ?>

    <?php wp_pagenavi(); ?>

    <?php else : ?>

    <?php if ( $wp_query->max_num_pages > 1 ) : ?>

    <nav class=”oldernewer”>

    <div class=”older”>

    <?php next_posts_link(‘« Older Entries’) ?>

    </div><!–.older–>

    <div class=”newer”>

    <?php previous_posts_link(‘Newer Entries »’) ?>

    </div><!–.newer–>

    </nav><!–.oldernewer–>

    <?php endif; ?>

    <?php endif; ?>

    <!– Page navigation –>

    <?php $wp_query = null; $wp_query = $temp;?>

    </div><!– #content –>

    <!– end #main –>

    <?php get_footer(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Display Page : Sort by Menu order’ is closed to new replies.