织梦Dedecms系统实现按“字母检索”搜索功能(2)


//加入数据库的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');";

通过系统函数GetPingyin获得文章标题的拼音首字母,并生成insert语句,保存标题拼音首字母到pytitle字段。

类似,修改article_eidt_action.php为:

//用拼音命名
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'; ";

第三步,修改首页模板,或者其它需要使用这个功能的模板。

<div>中文按声母排列:<a href=http://www.dede58.com/"/plus/search.php?keyword=a&searchtype=pytitle">A</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=b&searchtype=pytitle">B</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=c&searchtype=pytitle">C</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=d&searchtype=pytitle">D</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=e&searchtype=pytitle">E</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=f&searchtype=pytitle">F</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=g&searchtype=pytitle">G</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=h&searchtype=pytitle">H</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=j&searchtype=pytitle">J</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=k&searchtype=pytitle">K</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=l&searchtype=pytitle">L</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=m&searchtype=pytitle">M</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=n&searchtype=pytitle">N</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=o&searchtype=pytitle">O</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=p&searchtype=pytitle">P</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=q&searchtype=pytitle">Q</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=r&searchtype=pytitle">R</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=s&searchtype=pytitle">S</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=t&searchtype=pytitle">T</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=w&searchtype=pytitle">W</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=x&searchtype=pytitle">X</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=y&searchtype=pytitle">Y</a> - <a href=http://www.dede58.com/"/plus/search.php?keyword=z&searchtype=pytitle">Z</a> <- 中文软件名按第一汉字声母排列</div>

其中关键部分为keyword=字母&searchtype=pytitle。

第四步,我们通过search.php实现搜索,dedecms不允许小于3个字符的搜索,因此我们要修改它。

修改/plus/search.php文件,修改的部分为红色:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/210cf0cd690a866ce598cb90e99eb4b7.html