当前位置 : 主页 > 网站建设 > 正文

DedeCMS搜索根据内容模型显示不同模板

原创

重庆seo2017-02-14 20:10:14阅读()dedecmsA+ / A-

DedeCMS搜索根据内容模型显示不同模板

       DedeCMS搜索是固定的模板,搜索结果也是全站范围。搜索页面不参与SEO排名,应用nofollow禁止蜘蛛抓取,title最好也不要写搜索词。下面介绍网站建设中根据不同的内容模型显示不同的模板。

建立常见问题内容模型及栏目

       常见问题FAQ应区别于其他模型,不然在搜索的时候出现问题,新建FAQ内容模型ID为7(根据实际情况修改);

       在模板文件夹里,常见问题FAQ用search_faq.htm模板,普通搜索用search.htm模板。

模板增加识别内容模型ID的JS代码

       在需要的模板(比如index.htm)</head>之前加入

<script language="javascript" type="text/javascript">
 function Check(){
  if(document.formsearch.channeltype.value=="1"){
   document.formsearch.action="{dede:field name='phpurl'/}/search.php";
  }else{
   document.formsearch.action="{dede:field name='phpurl'/}/search_faq.php";
  }
 }
</script>

       搜索表单代码

<form name="formsearch" action="" 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><!--文章模型id=1-->
   <option value='7'>FAQ</option><!--新增内容模型id=7-->
  </select>
  <button type="submit" class="search-submit">搜索</button>
 </div>
</form>

新增搜索/plus/search_faq.php,/include/arc.searchview_faq.class.php

       找到/plus/search.php,复制一份并更名为search_faq.php。

       打开search_faq.php,找到

 require_once(DEDEINC."/arc.searchview.class.php");

       更改为

 require_once(DEDEINC."/arc.searchview_faq.class.php");

       找到/include/arc.searchview.class.php,复制一份并更名为arc.searchview_faq.class.php。

       打开arc.searchview_faq.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_faq.htm";

    扩展阅读

    本文地址:https://www.vi586.com/web/385.html
    版权声明:原创文章,版权归重庆SEO吖七所有,欢迎分享本文,支持原创,转载请保留出处

    赞(2)