首页 > 新闻资讯 > 限制WordPress的搜索只搜特定分类中的文章

限制WordPress的搜索只搜特定分类中的文章

3条评论
标签:
更多

出于某些原因,如果你需要把某些分类排除在搜索之外时,你就需要对WordPress做一些小改动了。

把以下代码放入search.php模板文件中,把第三行的IDs换成你需要的分类ID:

<?php if( is_search() )  :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("s=$s&paged=$paged&cat=1,2,3");
endif; ?>

大功告成!

原文:How to: limit search to specific categories

* 版权声明:作者WordPress啦! 转载请注明出处。

#1
学到了点,不错。
#2
感谢分享。。收了
#3
不错

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.