实现WordPress分类搜索功能代码

yibin 2016-06-01 WordPress 692

wordpress默认搜索是全站搜索方式,对于分类文章多的网站,输入搜索关键词搜索出来的结果不够精确,在搜索结果中查找需要的文章也比较费时,而通过按分类搜索明显会更有效率,更利于百度强调的用户体验优化博客吧先前一直使用普通的全站搜索方式,现在已改为按分类搜索方式,效果可看博客吧顶部的搜索框。

实现Wordpress分类搜索功能代码

分类搜索实现代码

1
2
3
4
5
<form id="searchform" name="searchform" method="get" action="<?php bloginfo('home'); ?>/" >
	<?php $select = wp_dropdown_categories('class=search_select&show_option_all=全站搜索&orderby=name&hierarchical=0&selected=-1&depth=1′);?>
	<input type="text" name="s" id="s" maxlength="34″ value=""/>	
	<input type="image" value="" src="<?php bloginfo('template_url'); ?>/img/search.gif"/>
</form>

把上面的代码替换原来的搜索代码,然后再调整搜索框的CSS样式即可

扫码添加微信

13013082126 扫描微信 建站咨询 优化咨询