2014-07-09 145 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

相关问题