Dedecms document titles are sorted alphabetically

Source: Internet
Author: User

This is also a question about Dede modification. This is how to arrange the article according to the initials of the title pinyin. The effect is as follows ):Step 1: First, you must modify the database structure and add fields for storing pinyin.Modify the dede_archives table and add pytitle and varchar (250). The value can be null. The following is the SQL statement used to create a table. The red part is the new one. You can use phpMyAdmin to directly modify the table structure. 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 '', 'additional title'
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 '', 'keyword' 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 article title and save it to the database.The files to be modified include: article_add.php, article_add_action.php, article_edit.php, and article_eidt_action.php, which are the four files for adding and modifying article control respectively. Modify article_add.php:
<TD> <input name = "iscommend" type = "checkbox" id = "iscommend" value = "11" class = "NP"> recommended <input name = "isbold" Type = "checkbox" id = "isbold" value = "5" class = "NP"> bold <input name = "isjump" type = "checkbox"
Id = "isjump" value = "1" class = "NP"> redirect URL <input name = "upinyin" type = "checkbox" id = "upinyin" class = "NP" value = "1" Checked = "checked"> Save pinyin </TD> adds an option to save pinyin. Modify article_edit.php:
<TD> <input name = "iscommend" type = "checkbox" id = "iscommend" value = "11" class = "NP" <? PHP if ($ arcrow ["iscommend"]> 10) echo "checked" ;?>> Recommended <input name = "isbold" type = "checkbox" id = "isbold" value = "5" class = "NP" <? PHP if ($ arcrow ["iscommend"] = 5 | $ arcrow ["iscommend"] = 16)
Echo "checked" ;?>> Bold <input name = "isjump" type = "checkbox" id = "isjump" value = "1" class = "NP" <? PHP echo $ arcrow ["redirecturl"] = ""? "": "Checked";?> Jump URL
<Input name = "upinyin" type = "checkbox" id = "upinyin" class = "NP" value = "1" <? PHP if ($ arcrow ["pytitle"] <> "") echo "checked" ;?>> Save pinyin </TD>. Modify article_add_action.php to: // obtain the pinyin code of the title if ($ upinyin = 1)
$ Pytitle = str_replace ("_", "", getpinyin ($ title, 1 )); // SQL statement to join the database // ---------------------------------- $ inquery = "insert into #@__ archives (typeid, typeid2, sortrank, iscommend, ismake, channel, arcrank, click, money, title, publish title, 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', '$ category title',' $ color', '$ writer',' $ source', '$ litpic ', '$ pubdate',' $ senddate', '$ arcatt', '$ adminid', '0',' $ description ',' $ keyword', '$ templet ', '$ redirecturl',' $ pytitle'); "; use the system function getpingyin to obtain the first letter of the article title, generate an insert statement, and save the first letter of the title to the pytitle field. Similarly, modify article_eidt_action.php to: // name if ($ upinyin = 1) in pinyin)
$ Pytitle = str_replace ("_", "", getpinyin ($ title, 1 )); // update the database SQL statement // ---------------------------------- $ inquery = "Update #@__ archives settypeid = '$ typeid', typeid2 =' $ typeid2', sortrank = '$ sortrank ', redirecturl = '$ redirecturl', iscommend =' $ iscommend', ismake = '$ ismake', arcrank =' $ arcrank ', money =' $ money ', title = '$ title', color =' $ color', writer = '$ write', source =' $ source', litpic = '$ litpic ', pubdate = '$ pubdate', description =' $ description', KEYWORDS = '$ keyword', templet =' $ templet ', your title =' $ your title ', arcatt = '$ arcatt', pytitle =' $ pytitle' where
Id = '$ id ';";Step 3: Modify the homepage template or other templates that need to use this function.<Div> Chinese characters are arranged by initials: <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>
<-The Chinese software names are arranged by the initials of the first Chinese Character </div>. The key part is keyword = Letter & searchtype = pytitle.Step 4: search by using search. php. dedecms does not allow searches of less than 3 characters, so we need to modify it.Modify/plus/search. PHP file, the modified part is Red: // determine whether to search for if ($ searchtype <> "pytitle ") {if ($ keyword = "" | strlen ($ keyword) <3) {showmsg ("the keyword cannot be less than 3 bytes! ","-1 "); exit ();}}Step 5: modify and implement search.Modify/include/inc_arcsearch_view.php. Objective: To obtain the letter keyword, generate a new search condition, obtain the search type keyword ($ searchtype), and call different display templates. Okay, let's continue to modify it. The modification is as follows, and the red part is the added or modified part. Modify a function
Getkeywordsql () function, added: // The support for if ($ this-> searchtype = "pytitle") {$ kwsql. = "and #@__ archives. pytitle like '$ this-> keywords %' ";} It is recommended to put it in foreach ($ KS as $ K ){...} belowStep 6: Index by letter has been implemented through the above, but the system's search template is called, which is not suitable for indexing by letter. Therefore, we need to proceed further, added support for new templates.1. Modify/include/inc_arcsearch_view.php and Function
_ Construct () constructor. 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 target is to call the template defined by the global variable pai_templets_pysearch when $ searchtype = pytitle. 2. Modify the include/config_hand.php file. Add the global variable pai_templets_pysearch. // Pinyin search template $ pai_templets_pysearch
= 'Pylist.htm'. Then, you can add the pylist.htm template in the template folder to display the results of the letter list.Step 7: It's not over yet. What if I want to limit the display range? For example, I only want to show the software, or the display of a column goes further.In fact, search supports many parameters, such as $ typeid (column number), $ channeltype (article type number), and $ orderby (sorting method). Now you know what to do? I still don't know. The following is an example: <a href = "/plus/search. php? Keyword = A & searchtype = pytitle & typeid = 2 & $ channeltype = 3 & $ orderby = title "> A </a> what does it mean? Don't tell you, hey.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.