2017-04-10 103 views
0

我想列出自定义帖子类型中的帖子,像下面的布局。自定义wordpress循环

enter image description here

HTML下面这样的布局。

<div class="col-md-4 col-sm-6"> 
PROFILE - 1 

</div> 
<div class="col-md-4 col-sm-6"> 


    </div> 
<div class="col-md-4 col-sm-6"> 
PROFILE - 2 

    </div> 
<div class="col-md-4 col-sm-6"> 
PROFILE - 3 

    </div> 
<div class="col-md-4 col-sm-6"> 


    </div> 

<div class="col-md-4 col-sm-6"> 
    PROFILE - 4 

    </div> 

,你可以看到后再次格分隔符 “ - - 1个& PROFILE 2 PROFILE” 后 “PROFILE - 1” 有一个div分离再有就是 “2个人 - - 1个& PROFILE”。

基本上结构如下。

资料-1

VV

空空间(DIV基于COL-MD-4 COL-SM-6)

VV

曲线-2

VV

简介-3

VV

空空间(DIV基于COL-MD-4 COL-SM-6)

VV

资料-4-

我使用该环路作为自定义结构但我无法从Profile-2> Profile-3> Space point中获取它。

寻找有助于实现这一循环

我已经试过这到目前为止

<?php 
$args=array(
'post_type' => 'ourteam', 
'posts_per_page' => -1 
); 

    //Set up a counter 
    $counter = 0; 

    //Preparing the Loop 
    $query = new WP_Query($args); 


    //In while loop counter increments by one $counter++ 
    if($query->have_posts()) : while($query->have_posts()) : $query- 
    >the_post(); $counter++; 

    //We are in loop so we can check if counter is odd or even 
    if($counter % 2 == 0) : //It's even 
    ?> 


    <div class="col-md-4 col-sm-6"> 

    </div> 

    <div class="col-md-4 col-sm-6"> 

    <div class="cp-attorneys-style-2"> 

     <div class="frame"> <a href="<?php the_permalink(); ?>"><?php 
    the_post_thumbnail(''); ?></a> 

     <div class="caption"> 

      <div class="holder"> 

      <ul> 

      <li><a href="<?php the_field('mem_twitter'); ?>"><i class="fa fa-twitter"></i></a></li> 

       <li><a href="<?php the_field('mem_facebook'); ?>"><i class="fa fa-facebook"></i></a></li> 

       <li><a href="<?php the_field('mem_linkedin'); ?>"><i class="fa fa-linkedin"></i></a></li> 

      </ul> 

      <p> </p> 

      <a href="<?php the_permalink(); ?>" class="btn-style-1">Read Profile</a> </div> 

     </div> 

     </div> 

     <div class="cp-text-box"> 

     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 

     <em><?php the_field('mem_titles'); ?></em> </div> 

    </div> 

    </div>  


<div class="col-md-4 col-sm-6"> 

</div> 


<?php 
else: //It's odd 
?> 



    <div class="col-md-4 col-sm-6"> 

    <div class="cp-attorneys-style-2"> 

     <div class="frame"> <a href="<?php the_permalink(); ?>"><?php 
     the_post_thumbnail(''); ?></a> 

     <div class="caption"> 

      <div class="holder"> 

      <ul> 

      <li><a href="<?php the_field('mem_twitter'); ?>"><i class="fa fa-twitter"></i></a></li> 

       <li><a href="<?php the_field('mem_facebook'); ?>"><i class="fa fa-facebook"></i></a></li> 

       <li><a href="<?php the_field('mem_linkedin'); ?>"><i class="fa fa-linkedin"></i></a></li> 

      </ul> 

      <p> </p> 

      <a href="<?php the_permalink(); ?>" class="btn-style-1">Read Profile</a> </div> 

     </div> 

     </div> 

     <div class="cp-text-box"> 

     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 

     <em><?php the_field('mem_titles'); ?></em> </div> 

    </div> 

    </div>  



    <?php 


    endif; 

    endwhile; wp_reset_postdata(); endif; 


    ?> 
+1

的全部价值? –

+0

@ hardik solanki我有更新我的问题,请参阅 – greenarrow

+0

默认情况下,引导使用了12列结构。如果你使用'col-md-4 col-sm-6',那么它将在Ipad中显示3个div和2个div。所以在你的情况下,它会像你的截图一样显示。 –

回答

0

清单自定义信息不那么复杂。你所要做的就是使用WP_Query函数查询自定义文章,然后以html格式列出。这里是你可以实现你想要的代码。

<?php 
    global $the_query; 

    $args = array (
      'post_type'=>'team', 
      'posts_per_page'=>-1, 
    ); 
    // You can change your post type and for more 
    // go to this link https://codex.wordpress.org/Class_Reference/WP_Query 
    $the_query = new WP_Query($args); ?> 
    <div class="container"> 
     <div class="row"> 
    <?php 
    if ($the_query->have_posts()) { 

     while ($the_query->have_posts()){ 
      $the_query->the_post(); ?> 

      <div class="col-md-4 col-sm-6"> 
     <?php echo get_the_title(get_the_ID()); ?> 

    </div> 
    <?php 
     }//end while 


    } //End if 
?> 
</div><!-- End of row --> 
</div><!-- End of container --> 

注: - 在循环中,你可以打印你所试图到目前为止做自定义后

+0

谢谢,但我想要的是一个自定义循环,我在我的问题 – greenarrow

+0

Content
中提到的结构将在循环中重复。一旦循环打印完所有信息。您需要使用css进行美化管理。 –

相关问题