wp搜索结果指定分类ID
七娃博客466人阅读
在某个特定栏目下,搜索时不想出现非相关的内容,就需要指定分类,排除其余的内容:例如在字体分类下,查找的结果必须全是字体,而不能是文章,或者素材的分类内容,这个功能很重要,那么怎么实现呢?
<form method="get" class="search-form inline" action="<?php bloginfo('url'); ?>"> <input class="search-field" placeholder="搜索问题" autocomplete="off" value="" name="s" required="true" type="search"> <input type="hidden" name="cat" value="3" /> <button type="submit" class="search-submit"><i class="iconfont icon-sousuo"></i> 搜</button> </form>
对就是<input type="hidden" name="cat" value="3" /> 这个限制了返回结果,cat=3就是仅查询分类id为3的数据,有人会说,我不知道当前分类id啊?办法有两个!
1.用代码自动获取当前分类的id:<?php echo get_current_category_id(); ?>
<input type="hidden" name="cat" value="<?php echo get_current_category_id(); ?>" />
2.去后台查看 分类目录——鼠标放到分类上,看左下角链接上的id
评论 | 0 条评论
登录之后才可留言,前往登录