0

我是PHP和WordPress世界中的新手,我创建的循环仅显示具有特定标记的帖子。在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

问题是,不工作,我的column2 div仍然是空的。为什么?你可以帮我吗?

TNX

安德烈

+0

请不要使用** ** query_posts使用wp_query代替 – 2013-03-19 12:16:06

回答

1

下面是使用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(); 
+0

不工作时, column2仍然无效:-( – AndreaNobili 2013-03-19 12:37:09

+0

尝试不带标签,也发布循环代码,在这样的page.php或single.php等等 – 2013-03-19 12:48:39

+0

当你说:“out the tag”时意味着什么? – AndreaNobili 2013-03-19 13:13:22

相关问题