织梦DedeCMS的搜索功能,默认情况下只搜索文章标题,而且是全站搜索。如果想改为搜索其他字段或者全文搜索,就需要修改织梦DedeCMS的设置,全文搜索还需要配置Sphinx服务器,不过对于大部分网站来说,全文搜索没有必要。
今天来分享一下如何解决织梦DedeCMS的分类搜索功能。分类搜索可以让用户更快的找到他想要的内容,这点对增强用户体验是非常有帮助的。实现的办法也不难,主要是要向织梦DedeCMS的搜索文件search.php文件传入分类id的值。
以织梦DedeCMS的默认模板为例,把默认模板文件夹中的head.htm文件的如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 |
< form action = "{dede:field name='phpurl'/}/search.php" name = "formsearch" >
< div class = "form" >
< h4 >搜索</ h4 >
< input type = "hidden" name = "kwtype" value = "0" />
< input name = "keyword" type = "text" class = "search-keyword" id = "search-keyword" />
< select name = "searchtype" class = "search-option" id = "search-option" >
< option value = "titlekeyword" selected = '1' >智能模糊搜索</ option >
< option value = "title" >仅搜索标题</ option >
</ select >
< button type = "submit" class = "search-submit" >搜索</ button >
</ div >
</ form >
|
替换为下面的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
< form action = "{dede:field name='phpurl'/}/search.php" name = "formsearch" >
< div class = "form" >
< h4 >搜索</ h4 >
< input type = "hidden" name = "kwtype" value = "0" />
< input type = "hidden" name = "searchtype" value = "titlekeyword" />
< input name = "keyword" type = "text" class = "search-keyword" id = "search-keyword" />
< select name = "typeid" class = "search-option" id = "typeid" >
< option value = '0' selected = '1' >全部栏目</ option >
{dede:channelartlist typeid='top' }
{dede:type} < option value = '[field:id/]' >[field:typename/]</ option >{/dede:type}
{dede:channel type='son' noself='yes'}
< option value = '[field:id/]' >-[field:typename/]</ option >
{/dede:channel}
{/dede:channelartlist}
</ select >< button type = "submit" class = "search-submit" >搜索</ button >
</ div >
</ form >
|
可以看到,基本的结构什么的都是没有变化的,只是传入了typeid的值。