Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress循环分组_Php_Wordpress - Fatal编程技术网

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
        )
    );
    

    参考资料:

    能否显示
    模板部件/单曲的代码?