織夢(mèng)的搜索功能很好用,但有時(shí)候我們會(huì)需要一些特殊的搜索情況,例如我們網(wǎng)站中需要根據(jù)頻道不同,調(diào)用不同的搜索結(jié)果頁(yè)模板。本文就來(lái)教大家怎樣調(diào)用不同的搜索頁(yè)模板。dedecms本身自帶的模板有圖片模型、文章模型、軟件模型等,有時(shí)候?yàn)榱擞脩趔w驗(yàn)需要給搜索框加一個(gè)判定,例如搜索軟件模型的時(shí)候顯示軟件模型的模板,搜索文章模型的時(shí)候顯示文章模型的模板。
具體的實(shí)現(xiàn)代碼如下:
1.在head區(qū)域加入如下代碼:
<script language="javascript" type="text/javascript">function check(){if(document.formsearch.channeltype.value=="1")document.formsearch.action="{dede:field name='phpurl'/}/search.php"elsedocument.formsearch.action="{dede:field name='phpurl'/}/search_news.php"}</script> |
這段代碼主要用來(lái)判斷你選擇了什么頻道,根據(jù)你選擇的頻道的不同,來(lái)使用不同的搜索頁(yè)模板。
2.更改搜索代碼
<form name="formsearch" action="" data-ke-onsubmit="check();"><div class="form"><input type="hidden" name="kwtype" value="0" /><input name="q" type="text" class="search-keyword" id="search-keyword" value="{dede:global name='keyword' function='RemoveXSS(@me)'/}" /><select name="channeltype" id="channeltype" ><option value='1' selected='1'>新聞</option><option value='3'>軟件</option></select><button type="submit" class="search-submit">搜索</button></div></form> |
其中重點(diǎn)就是
<select name="channeltype" id="channeltype" ><option value='1' selected='1'>新聞</option><option value='3'>軟件</option></select> |
關(guān)鍵設(shè)置:這里設(shè)置的按模型搜索 1是文章模型 3是軟件模型
3.復(fù)制/plus/serach.php 更名為 /plus/search_images.php
4.打開(kāi) search_images.php將如下代碼:
require_once(DEDEINC."/arc.searchview.class.php");
更改為
require_once(DEDEINC."/arc.searchimg.class.php");
5.復(fù)制 /include/arc.searchview.class.php 更名為 /include/arc.searchimg.class.php
6.打開(kāi) arc.searchimg.class.php查找如下代碼:
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
更改為
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search_images.htm
做完上面的操作,基本就可以調(diào)用出不同的搜索頁(yè)模板了。
本頁(yè)內(nèi)容由塔燈網(wǎng)絡(luò)科技有限公司通過(guò)網(wǎng)絡(luò)收集編輯所得,所有資料僅供用戶參考了本站不擁有所有權(quán),如您認(rèn)為本網(wǎng)頁(yè)中由涉嫌抄襲的內(nèi)容,請(qǐng)及時(shí)與我們聯(lián)系,并提供相關(guān)證據(jù),工作人員會(huì)在5工作日內(nèi)聯(lián)系您,一經(jīng)查實(shí),本站立刻刪除侵權(quán)內(nèi)容。本文鏈接:http://www.juherenli.com/4367.html