我正在尝试在一个自定义的帖子类型中列出帖子,就像下面这样的布局。

下面布局的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”之后又有"PROFILE -1& PROFILE - 2“div分隔符。
基本上结构如下。
配置文件-1
V V
空格(基于div的col-md-4 col-sm-6 )
V V
配置文件-2
V V
配置文件-3
V V
空格(基于div的col-md-4 col-sm-6 )
V V
配置文件-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;
?>发布于 2017-04-10 18:08:01
列出自定义帖子并不是那么复杂。您所要做的就是使用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 -->注意:-在循环中,您可以打印自定义post的所有值
https://stackoverflow.com/questions/43319922
复制相似问题