DedeCMS

这个功能主要实现的是用户在搜索的时候输入关键字,然后会出现下拉菜单,下拉菜单中出现的是站内所有包含这个关键字的文章的标题共用户选择,相对Dedecms原生的搜索这个功能实用一点,既增加了用户体验,也可以让用户快速的找到想要的东西。功能基于php+jquery来实现,参考autocomplete,效果图如下:



 下面讲解下具体实现步骤:

1、打开你的网站首页模板,在</head>之前加入

<span class="sh_keyword" style="color: rgb(165, 42, 42);"><script</span> <span class="sh_type" style="color: rgb(0, 0, 255);">language</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"javascript"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">type</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"text/javascript"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">src</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"{dede:global.cfg_templets_skin/}/js/jquery-1.7.1.min.js"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></script></span>
<span class="sh_keyword" style="color: rgb(165, 42, 42);"><script</span> <span class="sh_type" style="color: rgb(0, 0, 255);">type</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"text/javascript"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></span> 
    function lookup(inputString) { 
        if(inputString.length == 0) { 
            // Hide the suggestion box. 
            $('#suggestions').hide(); 
        } else { 
            $.post("/plus/search_list.php", {queryString: ""+inputString+""}, function(data){ 
                if(data.length >0) { 
                    $('#suggestions').show(); 
                    $('#autoSuggestionsList').html(data); 
                } 
            }); 
        } 
    } // lookup 
     
    function fill(thisValue) { 
        $('#inputString').val(thisValue); 
        setTimeout("$('#suggestions').hide();", 200); 
    } 
<span class="sh_keyword" style="color: rgb(165, 42, 42);"></script></span> 

  jquery-1.7.1.min.js这个jquery库需要你自己下载,这里就不多说了。

  这段代码中的search_list.php就是本文下载的文件,下载后放入/plus目录下。

2、打开head.htm,找到搜索部分的from表单代码修改为

<span class="sh_keyword" style="color: rgb(165, 42, 42);"><form</span>  <span class="sh_type" style="color: rgb(0, 0, 255);">name</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"formsearch"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">action</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"{dede:global.cfg_cmsurl/}/plus/search.php"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">id</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"formkeyword"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></span> 
          <span class="sh_keyword" style="color: rgb(165, 42, 42);"><label</span> <span class="sh_type" style="color: rgb(0, 0, 255);">for</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"header-subscribe-email"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">class</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"text"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></span> <span class="sh_keyword" style="color: rgb(165, 42, 42);"></label></span> 
          <span class="sh_keyword" style="color: rgb(165, 42, 42);"><input</span> <span class="sh_type" style="color: rgb(0, 0, 255);">type</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"hidden"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">name</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"kwtype"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">value</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"0"</span> <span class="sh_keyword" style="color: rgb(165, 42, 42);">/></span> 
          <span class="sh_keyword" style="color: rgb(165, 42, 42);"><input</span> <span class="sh_type" style="color: rgb(0, 0, 255);">type</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"text"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">name</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"q"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">size</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"24"</span>  <span class="sh_type" style="color: rgb(0, 0, 255);">value</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"在这里搜索..."</span> <span class="sh_type" style="color: rgb(0, 0, 255);">onfocus</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"if(this.value=='在这里搜索...'){this.value='';}"</span>  <span class="sh_type" style="color: rgb(0, 0, 255);">onblur</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"if(this.value==''){this.value='在这里搜索...';}"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">id</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"inputString"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">onkeyup</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"lookup(this.value);"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">onblur</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"fill();"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">class</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"f-text"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></span> 
          <span class="sh_keyword" style="color: rgb(165, 42, 42);"><input</span> <span class="sh_type" style="color: rgb(0, 0, 255);">type</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"submit"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">class</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"commit"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">value</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"搜索"</span> <span class="sh_keyword" style="color: rgb(165, 42, 42);">/></span> 
          <span class="sh_keyword" style="color: rgb(165, 42, 42);"><div</span> <span class="sh_type" style="color: rgb(0, 0, 255);">class</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"suggestionsBox"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">id</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"suggestions"</span> <span class="sh_type" style="color: rgb(0, 0, 255);">style</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"display: none;"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></span> 
            <span class="sh_keyword" style="color: rgb(165, 42, 42);"><div</span> <span class="sh_type" style="color: rgb(0, 0, 255);">class</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"suggestionList"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">><ul</span> <span class="sh_type" style="color: rgb(0, 0, 255);">id</span><span class="sh_symbol">=</span><span class="sh_string" style="color: rgb(255, 0, 255);">"autoSuggestionsList"</span><span class="sh_keyword" style="color: rgb(165, 42, 42);">></ul></div></span> 
          <span class="sh_keyword" style="color: rgb(165, 42, 42);"></div></span> 
        <span class="sh_keyword" style="color: rgb(165, 42, 42);"></form></span> 

  这部分可以根据你自己的代码的实际情况具体修改,主要是输入关键字的input和下边加的DIV层。

3、打开你自己的样式表css文件,在最后加入

<span class="sh_selector" style="color: rgb(34, 95, 45);">.suggestionsBox</span> <span class="sh_cbracket">{</span> <span class="sh_property" style="color: rgb(165, 42, 42);">position:</span><span class="sh_value" style="color: rgb(255, 0, 255);">relative</span>; <span class="sh_property" style="color: rgb(165, 42, 42);">left:</span><span class="sh_value" style="color: rgb(255, 0, 255);">0px</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">width:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">250px</span>; <span class="sh_property" style="color: rgb(165, 42, 42);">background:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">white</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">border:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">1px</span> <span class="sh_value" style="color: rgb(255, 0, 255);">solid</span> <span class="sh_string" style="color: rgb(255, 0, 255);">#dcdcdc</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">color:</span> <span class="sh_string" style="color: rgb(255, 0, 255);">#323232</span>; <span class="sh_property" style="color: rgb(165, 42, 42);">z-index:</span><span class="sh_value" style="color: rgb(255, 0, 255);">999</span>; <span class="sh_cbracket">}</span> 
<span class="sh_selector" style="color: rgb(34, 95, 45);">.suggestionList</span> <span class="sh_cbracket">{</span> <span class="sh_property" style="color: rgb(165, 42, 42);">margin:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">0px</span>; <span class="sh_property" style="color: rgb(165, 42, 42);">padding:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">0px</span>; <span class="sh_cbracket">}</span> 
<span class="sh_selector" style="color: rgb(34, 95, 45);">.suggestionList</span> li <span class="sh_cbracket">{</span> <span class="sh_property" style="color: rgb(165, 42, 42);">margin:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">0px</span> <span class="sh_value" style="color: rgb(255, 0, 255);">0px</span> <span class="sh_value" style="color: rgb(255, 0, 255);">3px</span> <span class="sh_value" style="color: rgb(255, 0, 255);">0px</span>; <span class="sh_property" style="color: rgb(165, 42, 42);">position:</span><span class="sh_value" style="color: rgb(255, 0, 255);">relative</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">padding:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">3px</span>; <span class="sh_property" style="color: rgb(165, 42, 42);">cursor:</span> <span class="sh_value" style="color: rgb(255, 0, 255);">pointer</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">list-style:</span><span class="sh_value" style="color: rgb(255, 0, 255);">none</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">padding-left:</span><span class="sh_value" style="color: rgb(255, 0, 255);">5px</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">height:</span><span class="sh_value" style="color: rgb(255, 0, 255);">20px</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">overflow:</span><span class="sh_value" style="color: rgb(255, 0, 255);">hidden</span><span class="sh_cbracket">}</span> 
<span class="sh_selector" style="color: rgb(34, 95, 45);">.suggestionList</span> li<span class="sh_symbol">:</span>hover <span class="sh_cbracket">{</span> <span class="sh_property" style="color: rgb(165, 42, 42);">background-color:</span> <span class="sh_string" style="color: rgb(255, 0, 255);">#659CD8</span>; <span class="sh_cbracket">}</span> 
<span class="sh_selector" style="color: rgb(34, 95, 45);">.jr</span><span class="sh_cbracket">{</span><span class="sh_property" style="color: rgb(165, 42, 42);">position:</span><span class="sh_value" style="color: rgb(255, 0, 255);">absolute</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">top:</span><span class="sh_value" style="color: rgb(255, 0, 255);">9px</span>;<span class="sh_property" style="color: rgb(165, 42, 42);">right:</span><span class="sh_value" style="color: rgb(255, 0, 255);">-5px</span><span class="sh_cbracket">}</span> 

  此样式可以根据自己的网站定义噢。

  到这添加的代码就完了,然后下载search_list.rar,下载后解压得search_list.php到放入/plus目录下。在这个文件里有详细注解。可根据实际情况调整。所有结果都是由这个文件来返回的。


### 配置和运行Dedecms于Nginx服务器 #### 安装依赖软件包 为了使Dedecms能够在基于Linux的操作系统上顺利运行,在开始之前需确保已经安装了必要的组件,如PHP、MySQL以及Nginx本身。对于CentOS 7.2 64位操作系统而言,可以通过yum命令来完成这些基础服务的安装[^1]。 #### 下载并解压Dedecms程序 获取最新版本的Dedecms压缩包,并将其上传至服务器指定位置;接着通过SSH登录到服务器终端界面,切换至存放压缩包的位置执行相应的解压指令。 #### 设置文件夹权限 针对特定目录设置合理的读写权限至关重要。特别是`data`, `templets`, `uploads`, 和其他可能涉及动态内容存储或用户提交数据处理的相关路径。应采用安全的方式调整它们的访问控制列表ACLs,防止潜在的安全风险。例如: ```bash chmod -R 755 /path/to/dede/data/ chmod -R 755 /path/to/dede/uploads/ ``` 同时,为了避免恶意脚本利用图片或其他资源类型的漏洞发起攻击,建议对某些敏感目录下的`.php`文件实施严格的访问限制措施。这可通过编辑Nginx站点配置文件实现,具体做法是在对应location块内加入如下规则以阻止任何尝试解析此类扩展名的行为: ```nginx location ~* ^/(data|templets|uploads|a|images)/.*\.(php|php5)$ { deny all; } ``` 此段配置应当放置在`location ~ \.php$ {...}`之上才能生效[^4]。 #### Nginx伪静态规则设定 为了让URL更加友好易记,通常会启用SEO友好的重写机制——即所谓的“伪静态”。对于使用Nginx作为Web容器的情况来说,可以参照官方文档或者其他社区贡献者分享的最佳实践案例来进行相应修改。以下是适用于Dedecms标签页(tag)的一个典型例子: ```nginx rewrite "^/tags$" /tags.php last; rewrite "^/tag-(.*)\.html$" /tags.php?/$1 last; ``` 请注意,当遇到因伪静态映射不当而导致的目标页面丢失(404错误)现象时,务必仔细核对自己所处的具体环境(IIS/Nginx/Apache),从而编写匹配度更高的转换逻辑[^3]。 #### 测试与验证 最后一步就是启动所有先前提到的服务进程,并打开浏览器输入目标域名/IP地址加上端口号(如果是默认80则可省略),按照提示逐步完成剩余初始化向导流程直至成功进入后台管理系统为止。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值