一次查询所有帖子,并设置一个计数器变量来检查您在循环中的位置。
$products = get_posts(
array(
\'numberposts\' => 7,
\'post_type\' => array(\'product\')
)
);
$count = 1;
foreach( $products as $product ):
if( $count == 1 ):
// first post
elseif( $count > 1 && $count < 5 ):
// two - four
else:
// four +
endif;
$count++;
endforeach;
编辑-使用标记:
$products = get_posts(
array(
\'numberposts\' => 7,
\'post_type\' => array(\'product\')
)
);
?>
<div class="class news">
<ul class="280">
<?php
$count = 1;
foreach( $products as $product ):
if( $count == 2 ):
?>
</ul>
</div>
<div class="class editorial">
<ul class="650">
<?php
elseif( $count == 5 ):
?>
</ul>
</div>
<div class="class images">
<ul class="980">
<?php
endif;
echo \'<li>post</li>\';
$count++;
endforeach;
?>
</ul>
</div>