Do not use query_posts()
!. 滤器pre_get_posts
相反*。
<?php
function wpse59617_filter_pre_get_posts( $query ) {
// Only modify the main query
if ( ! $query->is_main_query() ) { return $query; }
// Get the ID of the post to exclude
$slug = \'some-post-slug\';
$post_id = url_to_postid( $slug );
// Modify the query
$query->set( \'category_name\', \'Mycat\' );
$query->set( \'post__not_in\', $post_id );
$query->set( \'posts_per_page\', \'-1\' );
// Return the modified query
return $query;
}
add_filter( \'pre_get_posts\', \'wpse59617_filter_pre_get_posts\' );
?>
*不,真的:不要使用
query_posts()
.
Here\'s why.