Home >CMS Tutorial >DEDECMS >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!