dongshuo2752 2017-04-10 09:47
浏览 40

自定义wordpress循环

I'm trying to list posts in a custom post type, within a layout like following.

enter image description here

html for below layout like this.

 <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> 

as you can see after "PROFILE - 1" there is a div separator then there is "PROFILE - 1 & PROFILE - 2" after "PROFILE - 1 & PROFILE - 2" again div separator.

basically the structure as follows.

Profile-1

V V

Empty space (div based col-md-4 col-sm-6 )

V V

Profile-2

V V

Profile-3

V V

Empty space (div based col-md-4 col-sm-6 )

V V

Profile-4

i'm using this loop as a custom structure but i'm unable to get it from Profile-2 > Profile-3 > Space point.

looking for a help to achieve this loop

I have tried this so far

  <?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条回答 默认 最新

  • dsagzmosl32217092 2017-04-10 10:08
    关注

    Listing custom posts is not that complex. All you have to do is query the custom post using WP_Query Function and then list in html format. Here is the code using which you might achieve what you want.

        <?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 -->
    

    Note :- Inside the loop you can print all the value of custom post

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题