2015-11-02 93 views
-4

我目前遇到一些麻煩只有2個職位顯示在主頁上。如何在主頁上顯示2個帖子?

這些從網站上其他地方的活動頁面拉過來。

<div class="container"> 
     <div class="row">  

      <?php while (have_posts()) : the_post(); ?> 


      <?php endwhile; // End of the loop. ?> 

      <?php $whatson = new WP_Query(array(
      'post_type' => 'whats_on'  
       )); ?> 
      <?php while($whatson->have_posts()) : $whatson->the_post(); ?> 


    <div class="col-sm-12 col-md-5"> 
      <div class="thumbnail col-centered" style="width: 485px"> 

      <?php the_post_thumbnail('thumbnail') ?> 

       <div class="caption"> 
        <h3><?php the_title() ?></h3> 
        <h4><small></small></h4> 
        <p><?php the_field('whats_on_description'); ?></p> 
       </div><!--END caption--> 

      </div><!--END thumbnail--> 
     </div> 
    <?php endwhile; ?> 
</div><!--END row--> 

在此先感謝。我對這一切都很陌生。

+0

通常的帖子數量已被管理員面板設置決定的,但你可以硬編碼在'WP_Query'。 –

回答

0

試試這個代碼:

$whatson = new WP_Query(array('post_type' => 'whats_on','posts_per_page' => 2 )); 
+0

謝謝。非常感激。 – Dring

+0

隨時歡迎.. –

0

您是否嘗試添加'post_per_page'參數?

new WP_Query(array(
    'post_type' => 'whats_on', 
    'post_per_page' => 2 
)); 
相關問題