DEDE自定义搜索指定频道指定栏目搜索 按栏目搜索的方法
作者:达特 日期:2023-05-25 分类:CMS教程
对于综合性站点来说,因为栏目过多,而访客关注的内容可能不同,比如有的网站是门户网站,里面分不同的城市,而不同城市的访客,可能只想搜索自己城市的新闻内容,对于这个就需要对搜索功能进行定制。
首先我们看看怎么对DEDE的搜索功能进行指定栏目或者频道
在搜索结果页添加:
<input type="hidden" name="typeid" value="1,4″ />
value="1,4″就是你要指定的一个或多个栏目,多个栏目用,号隔开。
例如:
1 |
<form name="formsearch" action="{dede:global.cfg_cmsurl/}/plus/search.php"> |
4 |
<input type="hidden" name="kwtype" value="0″ /> |
5 |
<input type="hidden" name="typeid" value="1,4″ /> |
6 |
<input name="q" type="text" class="search-keyword" id="search-keyword" value="在这里搜索…" onfocus="if(this.value=='在这里搜索…'){this.value=";}" onblur="if(this.value=="){this.value='在这里搜索…';}" /> |
7 |
<button type="submit" class="search-submit">搜索</button> |
|
知道了这个原理,那接下来我们就可以制定对全站所有栏目进行调用,让访客可以自己选择要搜索哪个栏目
生成栏目列表供访客选择,完整代码如下
01 |
<form action="{dede:field name='phpurl'/}/search.php" name="formsearch"> |
04 |
<input type="hidden" name="kwtype" value="0" /> |
05 |
<input type="hidden" name="searchtype" value="titlekeyword" /> |
06 |
<input name="keyword" type="text" class="search-keyword" id="search-keyword" /> |
07 |
<select name="typeid" class="search-option" id="typeid"> |
08 |
<option value='0' selected='1'>全部栏目</option> |
09 |
{dede:channelartlist typeid='top' } |
10 |
{dede:type} <option value='[field:id/]'>[field:typename/]</option>{/dede:type} |
11 |
{dede:channel type='son' noself='yes'} |
12 |
<option value='[field:id/]'>-[field:typename/]</option> |
14 |
{/dede:channelartlist} |
15 |
</select><button type="submit" class="search-submit">搜索</button> |
|