2017-04-10 86 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進行美化管理。 –

相關問題