精确匹配你的三个<ul>
模式您可以执行以下操作:
$my_query = new WP_Query();
$my_query->query($args);
$skip = 2;
echo \'<ul>\';
while ($my_query->have_posts()) {
$my_query->the_post();
echo \'<li>\'.$post->post_title.\'</li>\';
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
break;
}
}
echo \'</ul>\';
echo \'<ul>\';
while ($my_query->have_posts()) {
$my_query->the_post();
echo \'<li>\'.$post->post_title.\'</li>\';
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
break;
}
}
echo \'</ul>\';
echo \'<ul>\';
while ($my_query->have_posts()) {
$my_query->the_post();
echo \'<li>\'.$post->post_title.\'</li>\';
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
break;
}
}
echo \'</ul>\';
然而,下面它更小、更整洁,并且应该创建任意数量的
<ul>
s取决于查询的大小,我假设这就是您所说的“以这种方式无限循环”的意思。
$my_query = new WP_Query();
$my_query->query($args);
$skip = 2;
while ($my_query->have_posts()) {
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
echo \'<ul>\';
}
$my_query->the_post();
echo \'<li>\'.$post->post_title.\'</li>\';
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
echo \'</ul>\';
}
}
使用单个
<ul>
$my_query = new WP_Query();
$my_query->query($args);
$skip = 2;
echo \'<ul>\';
while ($my_query->have_posts()) {
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
echo \'<li>\';
}
$my_query->the_post();
echo \'<div>\'.$post->post_title.\'</div>\';
if ( ( ($my_query->current_post-1) % $skip ) == 0) {
echo \'</li>\';
}
}
echo \'</ul>\';
The
$args
我过去测试的是。。。
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 8,
\'order\' => \'ASC\',
);
。。。但这应该适用于您提供的任何产品。
它确实假设您不想为每个循环查询一组不同的帖子。
显然,我并没有将其应用到您现有的代码中,但该模式应该很容易应用。