Loop returning only 1 result

时间:2014-12-28 作者:lordsnowgoose

我不知道为什么在运行循环时只返回1个结果。这是我的代码:

    <?php
    if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
        // Include the featured content template.
        get_template_part( \'featured-content\' );
    }

            if ( is_home() ) {
                query_posts( "page_id=5" );
            }

    $args2 = array(
        "page_id" => 5
    );
    $wp_query2 = new WP_Query($args2);
    if ( $wp_query2->have_posts() ) :
                // Start the Loop.
                while ( $wp_query2->have_posts() ) : the_post();

                    $wp_query2->the_post();
                    //echo \'<h1>\'.get_the_title().\'</h1>\';
                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                     get_template_part( \'content\', get_post_format() );

                endwhile;
                //wp_reset_post_data();
                // Previous/next post navigation.
                twentyfourteen_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( \'content\', \'none\' );

            endif;

$args = array(
        "ord" => "asc",
        "order_by" => "title",
        "cat" => 2,
        "posts_per_page" => 10,
        );
        $wp_query = new WP_Query($args);
            if ( $wp_query->have_posts() ) :
                // Start the Loop.
                while ( $wp_query->have_posts() ) : the_post();

                    $wp_query->the_post();
                    //echo \'<h1>\'.get_the_title().\'</h1>\';
                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                     get_template_part( \'content\', get_post_format() );

                endwhile;
                //wp_reset_post_data();
                // Previous/next post navigation.
                twentyfourteen_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( \'content\', \'none\' );

            endif;
?>
顺便说一下,我有两个循环,第二个循环需要返回多个结果。我还在索引中运行此代码。php的我的主题,它是基于二零一四年。

1 个回复
SO网友:Steven

在代码的顶部wp_reset_postdata();.

如中所述Functional Reference 它改变了主回路,应该避免。看来这就是你的问题所在。

结束

相关推荐

The Loop in Static Page

我对环路有一些问题。我以“Twenty14”主题为例。我正在使用基本循环创建2个php文件。一个是家。其中一个是名为示例页的模板页。php。两者都包含此代码;if( have_posts() ) : while( have_posts() ) : the_post(); the_content; endwhile; endif; 没什么特别的,唯一的区别是我在示例页面上有模板声明。php/** * Template Nam