2014-07-09 144 views
0

我有一個自定義帖子類型,使用高級自定義字段來使用戶能夠輸入內容。我想獲得所有帖子,並連續顯示3條帖子。讓說:獲取所有wordpress帖子並連續顯示3個帖子

<div class="row"> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
</div> 
<div class="row"> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
</div> 
... 

的問題是,它顯示在<div class="row"></div>都像這樣的帖子:

<div class="row"> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
    <div class="col-md-4">...</div> 
    ... 
</div> 

下面是我的代碼,我到目前爲止已經試過:

<div class="row"> 
    <?php 
     $args = array(
      'post_type' => 'team', 
      'order' => 'ASC' 
     ); 
     $the_query = new WP_Query($args); 

     while ($the_query->have_posts()) { 
      $the_query->the_post(); 
      get_template_part('content', 'team'); 
     } 
    ?> 
</div> 

我的內容_team.php:

<div class="col-md-4"> 
    <h3><?php the_field('name'); ?></h3> 
    <img src="<?php the_field('photo'); ?>" alt="<?php the_field('name'); ?>" /> 
    <p class="smallTitle"><?php the_field('position'); ?></p> 
    <p><?php the_field('biography'); ?></p> 
</div> 
+0

3使用MOD顯示這個網站 – Khushboo

+0

你能告訴我怎麼樣? –

回答

1

嘗試以下: -

<div class="row"> 
<?php 
$i = 1; 
while ($the_query->have_posts()) { 

    $the_query->the_post(); 
     get_template_part('content', 'team'); 

if ($i % 3 == 0){ ?> 
</div><div class="row"> 
<?php } ?> 
<?php $i++; ?> 
<?php } ?> 
+0

感謝Khushboo。我很新的wordpress主題。你已經做了一天 –

+0

歡迎:) – Khushboo

相關問題