2013-01-16 116 views
0

我已使用以下代碼顯示每篇帖子的帖子。使用wp_query顯示每個帖子類型的兩篇帖子

$post_types = array('a', 's','d','f','g');//post type names 
    foreach($post_types as $post_type) : 
    // The Query 
    $the_query = new WP_Query(array( 'post_type' => $post_type, 
            'orderby' => 'post_date', 
            'order' => 'DESC', 
            )); 
    // The Loop 
    ?> 
    <?php 
    while ($the_query->have_posts()) : $the_query->the_post(); ?> 
    <?php if (has_post_thumbnail()) : ?> 
    <div class="issue-content masonItem <?php echo $post_type; ?>"> 
     <?php 
     $url = wp_get_attachment_url(get_post_thumbnail_id()); 
     $resizedUrl = get_bloginfo('template_url')."/libs/timthumb.php?src=".$url."&amp;w=327&amp;h=204&amp;zc=1"; ?> 
     <a href="<?php echo $post_type == 'news' ? site_url('/news') : the_permalink(); ?>"><img src="<?php echo $resizedUrl; ?>" alt="<?php the_title(); ?>" class="masonry-thumb" /></a> 

     <?php get_template_part('content-issues', 'page');?> 
    </div><!--issue-content--><!--Mason Item--> 
    <?php endif; ?> 
    <?php endwhile; 

現在我想顯示每個帖子類型的2個帖子。我怎樣才能做到這一點 ?我得到了$ post_count的想法。但我不知道在我的代碼中使用它。

回答

0

試試這個:

'posts_per_page' => 2, 
0

你試試這

$the_query = new WP_Query(array( 'post_type' => $post_type,'orderby' => 'post_date','posts_per_page' => 2,'order' => 'DESC')); 
相關問題