POST TIME:2017-11-13 00:33
織夢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的值。
