关于query_post导致is_home()、is_paged()等判断失效
在主题制作过程中,难免有时候要调整输出文章的条数,从而需要使用到query_post,但是经过今天一翻周折,发现它会引起诸如is_home()、is_paged()、is_single()、is_category()、is_tag()等WP内至函数失效。 通常我们会使用类似如下的代码: <?php query_posts(‘showposts=10′); ?> //我们在开始时加上让他显示10条的操作 <?php while (have_posts()) : the_post(); ?> //里面是你需要的一些输出什么的,内容我就不详细写了。 <?php endwhile;?> 在运用了query_post后,再进行判断,常常容易引起判断失误,既然我们知道是query_post引起的,为避免这个现象应及时在 endwhile; 后加上 wp_reset_query(); 来跳出query。看如下代码: <?php query_posts(‘showposts=10′); ?> //我们在开始时加上让他显示10条的操作 <?php while (have_posts()) : the_post(); ?> //里面是你需要的一些输出什么的,内容我就不详细写了。 <?php endwhile;?> <?php wp_reset_query(); ?> 一切又恢复了往日的宁静。 来自:http://www.ctusky.com/12/0742/