我正在尝试创建一个自定义主页,其中网站内容显示如下。。。
请参见图像。。。
http://i.stack.imgur.com/ykrdf.png
使用单独的循环,这很简单。。。在类别获取循环中有3个单独的查询帖子。。。但我想将每个类别的查询帖子数量从3个减少到1个,因为它们来自同一类别。。。
这是否可能。。。(因为我不知道如何用div类块包装3个迭代)
我正在尝试创建一个自定义主页,其中网站内容显示如下。。。
请参见图像。。。
http://i.stack.imgur.com/ykrdf.png
使用单独的循环,这很简单。。。在类别获取循环中有3个单独的查询帖子。。。但我想将每个类别的查询帖子数量从3个减少到1个,因为它们来自同一类别。。。
这是否可能。。。(因为我不知道如何用div类块包装3个迭代)
可以通过检查循环中的位置并在适当的时间输出标记来实现这一点。在保存查询结果的对象中,有一个计数器跟踪当前帖子,$wp_query->current_post
. 请注意,它的索引为零,因此第一个是0,第二个是1,以此类推。。
<?php
while( have_posts() ):
the_post();
if( $wp_query->current_post == 0 ):
// this is the first post
?>
<div class="one">
<?php the_title(); ?>
</div>
<div class="two">
<?php
elseif( $wp_query->current_post > 0 && $wp_query->current_post < 4 ):
// this is the second - fourth posts
the_title();
elseif( $wp_query->current_post == 3 ):
// this is the fourth post
?>
<!-- close div class=two -->
</div>
<?php
endif;
endwhile;
Try like this:
query_posts( \'posts_per_page=9\' );
$postcount = 1;
$firsttop = false;
$firstbottom = false;
$secondtop = false;
$secondbottom = false;
$thirdtop = false;
$thirdbottom = false;
while ( have_posts() ) : the_post();
if($postcount = 1){
if(!$firsttop){
//open first div...
$firsttop = true;
}
//call first post structure...
$postcount++;
if(!$firstbottom){
//close first div...
$firstbottom = true;
}
}
else if($postcount > 1 and $postcount < 5){
if(!$secondtop){
//open second div...
$secondtop = true;
}
//call first post structure...
$postcount++;
if(!$secondbottom){
//close second div...
$secondbottom = true;
}
}
else {
if(!$thirdtop){
//open third div...
$thirdtop = true;
}
//call third post structure...
$postcount++;
if(!$thirdbottom){
//close third div...
$thirdbottom = true;
}
}
endwhile;
// Reset Query
wp_reset_query();
好的,我正在创建一个业务列表网站,该网站使用列表“类型”的自定义分类法。我需要在分类法归档页面上显示两个循环,一个用于“赞助”列表,另一个用于常规列表。分类法存档:http://pastie.org/3187162分页功能:http://pastie.org/3187168这两部分都在做我想做的事情,但有一个问题:在一个特定类别中大约有50个非赞助商列表,但第二个查询最多有5个“页面”(即,如果我将posts\\u per\\u page设置为5,则有25个列表,如果我将posts\\u per\\u p