而不是黑客索引。php为什么不使用pre\\u get\\u posts过滤器?
add_filter(\'pre_get_posts\', \'filter_homepage_posts\');
function filter_homepage_posts($query) {
$limit_number_of_posts = 5;
$featured_category_id = get_cat_id(\'Reviews\'); // by cat name...
if ($query->is_home) {
$query->set(\'cat\', $featured_category_id);
$query->set(\'showposts\', $limit_number_of_posts);
}
return $query;
}
复制自:
http://www.seanbehan.com/intercepting-the-wordpress-loop应该也是这样,因为从技术上讲,查询是通过引用传递的
add_action(\'pre_get_posts\', \'filter_homepage_posts\');
function filter_homepage_posts( $query) {
$limit_number_of_posts = 5;
$featured_category = \'bacon-category\'; // by cat slug...
if ($query->is_home) {
$query->set(\'category_name\', $featured_category);
$query->set(\'showposts\', $limit_number_of_posts);
}
return $query;
}