2013-03-15 57 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

相关问题