Dreamweaver dedecms implements alphabetical index search function
DEDE system has "alphabetic index" function
The implementation method is as follows
Step one: First, you must modify the database structure and add a field to store Pinyin. (Recommended learning: (CMS )
Modify the DEDE_ARCHIVES table, add pytital, Varchar (250), allowed to be empty. The following is the SQL to create the table, for reference only. The red part is the new part, which can be implemented by directly modifying the table structure with phpmyadmin.
CREATE TABLE `dede_archives` ( `ID` int(11) unsigned NOT NULL auto_increment, `typeid` int(11) unsigned NOT NULL default ‘0′, `typeid2` int(11) unsigned NOT NULL default ‘0′, `sortrank` int(11) NOT NULL default ‘0′, `iscommend` smallint(6) NOT NULL default ‘0′, `ismake` smallint(6) NOT NULL default ‘0′, `channel` int(11) NOT NULL default ‘1′, `arcrank` smallint(6) NOT NULL default ‘0′, `click` int(11) unsigned NOT NULL default ‘0′, `money` smallint(6) NOT NULL default ‘0′, `title` varchar(80) NOT NULL default ”, `shorttitle` varchar(36) NOT NULL default ”, `color` varchar(10) NOT NULL default ”, `writer` varchar(30) NOT NULL default ”, `source` varchar(50) NOT NULL default ”, `litpic` varchar(100) NOT NULL default ”, `pubdate` int(11) NOT NULL default ‘0′, `senddate` int(11) NOT NULL default ‘0′, `arcatt` smallint(6) NOT NULL default ‘0′, `adminID` int(11) NOT NULL default ‘0′, `memberID` int(11) unsigned NOT NULL default ‘0′, `description` varchar(250) NOT NULL default ”, `keywords` varchar(60) NOT NULL default ”, `templet` varchar(60) NOT NULL default ”, `lastpost` int(11) NOT NULL default ‘0′, `postnum` int(11) NOT NULL default ‘0′, `redirecturl` varchar(150) NOT NULL default ”, `mtype` int(11) NOT NULL default ‘0′, `userip` varchar(20) NOT NULL default ”, `locklikeid` smallint(6) NOT NULL default ‘0′, `likeid` varchar(240) default ”, `pytitle` varchar(250) default NULL, PRIMARY KEY (`ID`), KEY `click` (`click`), KEY `senddate` (`senddate`), KEY `typeid` (`typeid`), KEY `arcrank` (`arcrank`), KEY `sortrank` (`sortrank`), KEY `pubdate` (`pubdate`), KEY `litpic` (`litpic`), KEY `typeid2` (`typeid2`) ) ENGINE=MyISAM DEFAULT CHARSET=gbk;
Step 2: Get the first letter of the pinyin of the article title and save it to the database.
The files that need to be modified are:
article_add.php、article_add_action.php、article_edit.php、article_eidt_action.php
are the four files controlled by adding new articles and modifying articles respectively.
Modify article_add.php to:
<td> <input name=”iscommend” type=”checkbox” id=”iscommend” value=”11″> 推荐 <input name=”isbold” type=”checkbox” id=”isbold” value=”5″> 加粗 <input name=”isjump” type=”checkbox” id=”isjump” value=”1″ onClick=”ShowUrlTr()”> 跳转网址 <input name=”upinyin” type=”checkbox” id=”upinyin” value=”1″ checked=”checked”>保存拼音 </td>
Add an option to save pinyin.
Modify article_edit.php to:
<td> <input name=”iscommend” type=”checkbox” id=”iscommend” value=”11″<?php if($arcRow["iscommend"]>10) echo ” checked”;?>> 推荐 <input name=”isbold” type=”checkbox” id=”isbold” value=”5″<?php if($arcRow["iscommend"]==5||$arcRow["iscommend"]==16) echo ” checked”;?>> 加粗 <input name=”isjump” onClick=”ShowUrlTrEdit()” type=”checkbox” id=”isjump” value=”1″<?php echo $arcRow["redirecturl"]==”" ? “” : ” checked”;?>> 跳转网址 <input name=”upinyin” type=”checkbox” id=”upinyin” value=”1″<?php if($arcRow["pytitle"]<>”") echo ” checked”;?>> 保存拼音 </td>
Same as above.
Modify article_add_action.php to:
//获得标题的拼音码 if($upinyin==1) $pytitle = str_replace(“_”,”",GetPinyin($title,1)); //加入数据库的SQL语句 //———————————- $inQuery = “INSERT INTO dede_archives( typeid,typeid2,sortrank,iscommend,ismake,channel, arcrank,click,money,title,shorttitle,color,writer,source,litpic, pubdate,senddate,arcatt,adminID,memberID,description,keywords,templet,redirecturl,pytitle) VALUES (‘$typeid’,'$typeid2′,’$sortrank’,'$iscommend’,'$ismake’,'$channelid’, ‘$arcrank’,'0′,’$money’,'$title’,'$shorttitle’,'$color’,'$writer’,'$source’,'$litpic’, ‘$pubdate’,'$senddate’,'$arcatt’,'$adminID’,'0′,’$description’,'$keywords’,'$templet’,'$redirecturl’,‘$pytitle’);”;
Get the pinyin initials of the article title through the system function GetPingyin, generate an insert statement, and save the pinyin initials of the title to the pytitle field .
Similarly, modify article_eidt_action.php to:
//用拼音命名 if($upinyin==1) $pytitle = str_replace(“_”,”",GetPinyin($title,1)); //更新数据库的SQL语句 //———————————- $inQuery = ” update dede_archives set typeid=’$typeid’, typeid2=’$typeid2′, sortrank=’$sortrank’, redirecturl=’$redirecturl’, iscommend=’$iscommend’, ismake=’$ismake’, arcrank=’$arcrank’, money=’$money’, title=’$title’, color=’$color’, writer=’$writer’, source=’$source’, litpic=’$litpic’, pubdate=’$pubdate’, description=’$description’, keywords=’$keywords’, templet=’$templet’, shorttitle=’$shorttitle’, arcatt=’$arcatt’, pytitle=’$pytitle’ where ID=’$ID’; “;
The third step is to modify the homepage template, or other templates that need to use this function.
<div>中文按声母排列:<a href=”/plus/search.php?keyword=a&searchtype=pytitle”>A</a> – <a href=”/plus/search.php?keyword=b&searchtype=pytitle”>B</a> – <a href=”/plus/search.php?keyword=c&searchtype=pytitle”>C</a> – <a href=”/plus/search.php?keyword=d&searchtype=pytitle”>D</a> – <a href=”/plus/search.php?keyword=e&searchtype=pytitle”>E</a> – <a href=”/plus/search.php?keyword=f&searchtype=pytitle”>F</a> – <a href=”/plus/search.php?keyword=g&searchtype=pytitle”>G</a> – <a href=”/plus/search.php?keyword=h&searchtype=pytitle”>H</a> – <a href=”/plus/search.php?keyword=j&searchtype=pytitle”>J</a> – <a href=”/plus/search.php?keyword=k&searchtype=pytitle”>K</a> – <a href=”/plus/search.php?keyword=l&searchtype=pytitle”>L</a> – <a href=”/plus/search.php?keyword=m&searchtype=pytitle”>M</a> – <a href=”/plus/search.php?keyword=n&searchtype=pytitle”>N</a> – <a href=”/plus/search.php?keyword=o&searchtype=pytitle”>O</a> – <a href=”/plus/search.php?keyword=p&searchtype=pytitle”>P</a> – <a href=”/plus/search.php?keyword=q&searchtype=pytitle”>Q</a> – <a href=”/plus/search.php?keyword=r&searchtype=pytitle”>R</a> – <a href=”/plus/search.php?keyword=s&searchtype=pytitle”>S</a> – <a href=”/plus/search.php?keyword=t&searchtype=pytitle”>T</a> – <a href=”/plus/search.php?keyword=w&searchtype=pytitle”>W</a> – <a href=”/plus/search.php?keyword=x&searchtype=pytitle”>X</a> – <a href=”/plus/search.php?keyword=y&searchtype=pytitle”>Y</a> – <a href=”/plus/search.php?keyword=z&searchtype=pytitle”>Z</a> <- 中文软件名按第一汉字声母排列</div>
The key part is keyword=letter&searchtype=pytitle.
The fourth step is to implement search through search.php. dedecms does not allow searches of less than 3 characters, so we need to modify it.
Modify the /plus/search.php file, the modified part is in red:
//判断是否为声母搜索 if($searchtype<>”pytitle”){ if($keyword==”"||strlen($keyword)<3){ ShowMsg(“关键字不能小于3个字节!”,”-1″); exit(); } }
The fifth step is to modify and implement the search.
Modify /include/inc_arcsearch_view.php, goal:
Obtain letter keywords, generate new search conditions, obtain search type keywords ($searchtype), and call different displays template.
Okay, let’s continue to modify it as follows. The red part is the new or modified part.
Modify the function GetKeywordSql() function and add:
//声母搜索支持 if($this->SearchType==”pytitle”){ $kwsql .= ” And dede_archives.pytitle like ‘$this->Keywords%’ “; }
It is recommended to place it under foreach($ks as $k){…}
Step six, through the above, alphabetical indexing has been implemented, but the system's search template is called, which is not suitable for the characteristics of alphabetical indexing, so we need to go one step further and add new template support.
1. Modify /include/inc_arcsearch_view.php and modify the function __construct() constructor. For:
if($this->SearchType==”pytitle”) $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'].”/”.$GLOBALS['cfg_df_style'].”/”.$GLOBALS['cfg_templets_pysearch']; else $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'].”/”.$GLOBALS['cfg_df_style'].”/search.htm”;
The goal is to determine when $searchtype==pytitle, call the template defined by the global variable cfg_templets_pysearch.
2. Modify the include/config_hand.php file. Add global variable cfg_templets_pysearch.
//拼音搜索模板 $cfg_templets_pysearch = ‘pylist.htm’;
Then you can add the pylist.htm template in the template folder to display the results of the alphabetical list.
Step seven, the matter is not over yet. What if I want to limit the scope of the display? For example, I only want to display software, or a certain column, to go one step further.
In fact, search supports many parameters, such as $typeid (column number), $channeltype (article type number), $orderby (sorting method), etc. Now you know what to do, right?
Don’t know yet, here is an example:
<a href=”/plus/search.php?keyword=a&searchtype=pytitle&typeid=2&$channeltype=3&$orderby=title”>A</a>
The above is the detailed content of Dreamweaver dedecms implements alphabetical index search function. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Solution to the failure of Dreamweaver CMS to connect to the database: 1. Check the database configuration and ensure that the relevant information of the database is correctly set in the /data/config.php file in the root directory of Dreamweaver CMS; 2. Test the database connection by creating a A simple PHP script to test whether the database connection is successful; 3. Check the database server status and change the database server address in the /data/config.php file in the root directory of DreamWeaver CMS; 4. Check the network connection.

The security of DreamWeaver cms is relatively good for the following reasons: 1. Fast vulnerability repair; 2. CSRF (cross-site request forgery) protection; 3. XSS (cross-site scripting attack) protection; 4. SQL injection protection; 5. Code audit.

Dream Weaver CMS Station Group Practice Sharing In recent years, with the rapid development of the Internet, website construction has become more and more important. When building multiple websites, site group technology has become a very effective method. Among the many website construction tools, Dreamweaver CMS has become the first choice of many website enthusiasts due to its flexibility and ease of use. This article will share some practical experience about Dreamweaver CMS station group, as well as some specific code examples, hoping to provide some help to readers who are exploring station group technology. 1. What is Dreamweaver CMS station group? Dream Weaver CMS

There is no charge for the Dreamweaver CMS system. Dreamweaver CMS is an open source content management system. Its core code is provided for free. Users can download the latest version of Dreamweaver CMS for free and obtain relevant technical support and documentation. However, during use, users may need to purchase additional functional modules or theme templates, which are chargeable. The price for purchasing these paid modules and templates depends on the specific functions and design complexity.

Title: Analysis of the reasons and solutions for why the secondary directory of DreamWeaver CMS cannot be opened. Dreamweaver CMS (DedeCMS) is a powerful open source content management system that is widely used in the construction of various websites. However, sometimes during the process of building a website, you may encounter a situation where the secondary directory cannot be opened, which brings trouble to the normal operation of the website. In this article, we will analyze the possible reasons why the secondary directory cannot be opened and provide specific code examples to solve this problem. 1. Possible cause analysis: Pseudo-static rule configuration problem: during use

Dreamweaver CMS is a very popular website construction system with powerful functions, friendly interface and easy to use. But sometimes, we will find that to achieve some special needs, the functions it originally provided may not be enough. In response to this situation, we can carry out secondary development and realize personalized website needs through customized code. This article will share some secrets about the secondary development of DreamWeaver CMS to help you unlock the skills of personalized website customization. 1. Description of customization requirements for homepage carousel: original DreamWeaver CMS homepage

DedeCMS is a content management system widely used in website construction, providing rich functions and flexible customization. However, sometimes we need to delete some files in the database to clean up space or solve some problems. This article will introduce how to delete database files in Dreamweaver CMS and provide specific code examples. Step 1: Back up the database Before performing any database operations, be sure to back up the database to prevent accidents. You can use phpMyAdmin or other numbers

Title: Things to note when deleting database files of Dreamweaver CMS. As a popular website construction tool, the deletion of database files of Dreamweaver CMS is one of the problems often encountered in website maintenance. Incorrect database file deletion operations may result in website data loss or website failure to function properly. Therefore, we must be extremely cautious when performing database file deletion operations. The following will introduce the precautions for deleting Dreamweaver CMS database files, and provide some specific code examples to help you correctly delete database files. Note: prepare
