我试图在如下布局中以自定义帖子类型列出帖子。
下面的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>
正如您所看到的,在“PROFILE-1”之后有一个div分隔符,然后在“PROFILE-1&PROFILE-2”之后又有一个div分隔符“PROFILE-1&PROFILE-2”。
基本结构如下。
剖面图-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;
?>
最合适的回答,由SO网友:Rishabh 整理而成
您可以像这样设置自定义循环
$a=2;
//In while loop counter increments by one $counter++
if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
if($a%3!=0){ //Here write function to display title and discription
?>
<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
$a = $a+1;
} else {
?>
<div class="col-md-4 col-sm-6">
<?php //Leave this div empty
?>
</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>
<?php
$a = $a+2;
}
endwhile; wp_reset_postdata(); endif;
首先备份代码。