在我的主题中,我为用户提供了一个选项,可以设置一个“博客类别”,在index.php
使用WP_Query
:
$shortname = get_option(\'of_shortname\');
$cat_option = get_option($shortname.\'_cats_in_blog\');
$catid = get_cat_ID($cat_option);
$paged = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
$args = array(
\'cat\' => $catid,
\'paged\' => $paged
);
$query = new WP_Query( $args );
// Queries fine, but search stops working
while ( $query->have_posts() ) : $query->the_post();
// Loop stuff here
endwhile;
这很好,但搜索小部件坏了。我还尝试使用query_posts
但这有相反的效果;查询的类别未显示,但搜索仍起作用。下面是代码:$shortname = get_option(\'of_shortname\');
$cat_option = get_option($shortname.\'_cats_in_blog\');
$catid = get_cat_ID($cat_option);
// Search is working, querying is not
global $query_string; // required
$posts = query_posts($query_string.\'&posts_per_page=3&cat=$catid\');
while ( $query->have_posts() ) : $query->the_post();
// Loop stuff here
endwhile;
我检查了$catid
变量,它将返回应该返回的内容。我是以错误的方式还是在错误的地方提出质疑?非常感谢您的帮助,提前感谢。