Php Wordpress循环分组
我想在Php Wordpress循环分组,php,wordpress,Php,Wordpress,我想在标签中循环标签,并连续编号,但在每个标签中重复编号。 这是我的密码: $catquery = new WP_Query( 'cat=6&posts_per_page=2' ); if ( $catquery->have_posts() ) { if ( is_home() && is_front_page() ) { while ( $catquery->have_posts() ) { $catquery-
标签中循环
标签,并连续编号,但在每个
标签中重复编号。
这是我的密码:
$catquery = new WP_Query( 'cat=6&posts_per_page=2' );
if ( $catquery->have_posts() ) {
if ( is_home() && is_front_page() ) {
while ( $catquery->have_posts() ) {
$catquery->the_post();
get_template_part( 'template-parts/single-song', get_post_type() );
}
}
}
$catquery = new WP_Query( 'cat=6&posts_per_page=2' );
if ( $catquery->have_posts() ) {
if ( is_home() && is_front_page() ) {
while ( $catquery->have_posts() ) {
$catquery->the_post();
get_template_part( 'template-parts/single-song', get_post_type() );
}
}
}
wp_reset_postdata();
输出为:
<ul>
<li>Post 1</li>
<li>Post 2</li>
</ul>
<ul>
<li>Post 1</li>
<li>Post 2</li>
</ul>
- 职位1
- 职位2
- 职位1
- 职位2
简言之,我的预期输出应如下所示:
<ul>
<li>Post 1</li>
<li>Post 2</li>
</ul>
<ul>
<li>Post 3</li>
<li>Post 4</li>
</ul>
- 职位1
- 职位2
- 职位3
- 邮政4
模板部件/单曲文件包含:
<li></li>
您应该使用查询分页或偏移。另外,对参数使用数组语法:
使用分页:
$catquery = new WP_Query(
array(
'cat' => 6,
'posts_per_page' => 2,
'paged' => 2
)
);
带偏移量:
$catquery = new WP_Query(
array(
'cat' => 6,
'posts_per_page' => 2,
'offset' => 2
)
);
参考资料:能否显示
模板部件/单曲的代码?