循环在WordPress主题中只显示有标签的文章,不工作


Loop in WordPress theme that show only tagged articles, don't work

我是PHP和WordPress世界的新手,我有一个创建循环的问题,只显示具有特定标记的帖子。

在主页中,我将创建一个循环,只显示设置了特定标签的文章,因此我为wordpress实现了以下PHP循环:

   <div id="column2">
        <?php   
            query_posts( 'tag=sasha' );  
            if(have_posts()): 
                while (have_posts()): the_post(); 
        ?>  
        <?php endwhile; else: ?>  
        <?php endif; ?> 
   </div> <!-- end column2 -->

我在一篇文章中设置了一个标签:sasha

问题是不工作,我的column2div仍然是空的。为什么?你能帮我吗?

Tnx

Andrea

使用WP_QUERY时应该是这样的:

$args = array('tag' => 'sasha');
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) :
        $the_query->the_post();
        echo '<div>' . get_the_title() . '</div>';
        the_content();
endwhile;
wp_reset_postdata();