2013-03-15 59 views
0

以下代碼輸出帖子標題列表。在此列表下方,它還會輸出與類別8中的標籤「test」匹配的每個完整帖子。爲什麼它會輸出完整帖子?我如何防止這種情況發生?爲什麼WordPress的循環輸出完整的帖子?

$query_str = "cat=8&tag=test"; 
query_posts($query_str); 

while (have_posts()) : the_post(); 
    echo '<div><a href="'; 
    the_permalink(); 
    echo '">'; 
    the_title(); 
    echo '</a></div>'; 
endwhile; 
+0

你的意思是它的輸出'the_content'呢? – 2013-03-15 15:26:55

+0

是的,但沒有標題。 – 4thSpace 2013-03-15 15:28:04

回答

1

嘗試此大小,而不是使用query_posts這是錯誤使用WP_Query像這樣

$args = array('cat' => 8, 'tag' => 'test'); 

$the_query = new WP_Query($args); 

while ($the_query->have_posts()) : 
$the_query->the_post(); 
echo '<div><a href="'. get_permalink($the_query->post->ID).'"/>' . get_the_title() . '</a></div>'; 
endwhile; 


wp_reset_postdata(); 
+0

這打破了頁面。獲取全白頁。 – 4thSpace 2013-03-15 15:55:29

+0

我編輯它再試一次 – 2013-03-15 15:56:06

+0

不錯,作品。謝謝。 – 4thSpace 2013-03-15 16:06:11

相關問題