大家知道怎樣實(shí)現(xiàn)dede搜索結(jié)果頁按頻道模型顯示不同模板嗎,這問題網(wǎng)上看到不少朋友都在問,究竟怎樣才能實(shí)現(xiàn)呢,下面是麥站總結(jié)的些方法:
dedecms門戶模板的時(shí)候經(jīng)常會(huì)有圖片模型、文章模型、軟件模型之類的,要是給搜索框加一個(gè)判定,例如搜索軟件模型的時(shí)候顯示一個(gè)模板,搜索文章模型的時(shí)候顯示一個(gè)模板。
具體實(shí)現(xiàn)代碼:
1 在head區(qū)域加入
<script language="javascript" type="text/javascript">
<!--
function check(){
if(document.formsearch.channeltype.value=="3")
document.formsearch.action="{dede:field name='phpurl'/}/search_images.php"
else
document.formsearch.action="{dede:field name='phpurl'/}/search.php"
}
-->
</script>
2 更改搜索代碼
<form name="formsearch" action="" *****ubmit="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ù)制serach.php 更名為 search_images.php
4 打開 search_images.php
require_once(DEDEINC."/arc.searchview.class.php");
更改為
require_once(DEDEINC."/arc.searchimg.class.php");
5復(fù)制 arc.searchview.class.php 更名為 arc.searchimg.class.php
6 打開 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";
核心的修改已經(jīng)結(jié)束了,剩下的就是在search_images.htm這個(gè)模板里自由發(fā)揮了。
同理也可以實(shí)現(xiàn)按欄目type搜索顯示不同風(fēng)格的結(jié)果頁得。
大家不妨參考下修改下,這對(duì)于用戶體驗(yàn)很有幫助的