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

相關問題