您当前的位置: 主页 > 优化教程
方法一,织梦默认有这个函数,在include/inc/inc_fun_funAdmin.PHP中.即SpGetPinyin()
 
但他只能得到全拼,没法得到首字母,
 
用法举例
 
$pingyin=GetPinyin($row['title'],0,1); 
 
$a=substr(GetPinyin($row['title']),0,1);//得到拼音首字母 
 
 
方法二,如果你只想得到首字母,不需要全拼,还可以用以下函数得到首字母
 
if (ord($row['title'])>128) { //汉字开头 
 $letter=getfirstchar2($row['title']); 
}else if(ord($row['title'])>=48 and ord($row['title'])<=57){ //数字开头 
$letter=iconv_substr($title,0,1,'utf-8'); 
}
else if(ord($row['title'])>=65 and ord($row['title'])<=90){ //大写英文开头 
$letter=iconv_substr($row['title'],0,1,'utf-8'); 
}else if(ord($row['title'])>=97 and ord($row['title'])<=122){ //小写英文开头 
$letter=iconv_substr($row['title'],0,1,'utf-8'); 
$letter=strtoupper($letter);//字母转换成大写 
print_r($letter);exit; 
 function getfirstchar2($s0){ 
$s=iconv("UTF-8","gb2312", $s0);  
$asc=ord($s{0})*256+ord($s{1})-65536;  
if($asc>=-20319 and $asc<=-20284)return "A";  
if($asc>=-20283 and $asc<=-19776)return "B";  
if($asc>=-19775 and $asc<=-19219)return "C";  
if($asc>=-19218 and $asc<=-18711)return "D";  
if($asc>=-18710 and $asc<=-18527)return "E";  
if($asc>=-18526 and $asc<=-18240)return "F";  
if($asc>=-18239 and $asc<=-17923)return "G";  
if($asc>=-17922 and $asc<=-17418)return "H";  
if($asc>=-17417 and $asc<=-16475)return "J";  
if($asc>=-16474 and $asc<=-16213)return "K";  
if($asc>=-16212 and $asc<=-15641)return "L";  
if($asc>=-15640 and $asc<=-15166)return "M";  
if($asc>=-15165 and $asc<=-14923)return "N";  
if($asc>=-14922 and $asc<=-14915)return "O";  
if($asc>=-14914 and $asc<=-14631)return "P";  
if($asc>=-14630 and $asc<=-14150)return "Q";  
if($asc>=-14149 and $asc<=-14091)return "R";  
if($asc>=-14090 and $asc<=-13319)return "S";  
if($asc>=-13318 and $asc<=-12839)return "T";  
if($asc>=-12838 and $asc<=-12557)return "W";  
if($asc>=-12556 and $asc<=-11848)return "X";  
if($asc>=-11847 and $asc<=-11056)return "Y";  
if($asc>=-11055 and $asc<=-10247)return "Z";  
return false;  
}
 
三,如何实现文章列表中,按首字母进行归类归档排序?下面是完整代码
 
<div class="container padding-big"style="min-height:200px;"> 
<p>{dede:type }[field:typename/]{/dede:type}</p> 
<div> 
{dede:php}  
$sql = "select arc.id,arc.writer,arc.typeid, arc.title, arc.senddate,tp.sitepath,tp.namerule,tp.typedir from dede_archives  arc  left join `dede_arctype` tp on arc.typeid=tp.id where arc.typeid=2"; 
 $dsql->SetQuery($sql); 
$dsql->Execute();//执行SQL操作 
while($row = $dsql->GetArray()){ 
//print_r($row['title']);exit; 
//$pingyin=GetPinyin($row['title'],0,1); 
$letter=substr(GetPinyin($row['title']),0,1);//取得拼音首字母 
$letter=strtoupper($letter); 
  
$arr[$letter]['writer'][]=$row["writer"]; 
$arr[$letter]['url'][]=GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],0,0,$row['namerule'],$row['typedir'],0, '',0,'',$row['sitepath']); 
$arr[$letter]['title'][]=$row["title"];        
}  
ksort($arr);//字母排序 
//print_r($arr);exit; 
$b=1; 
foreach($arr as $k=>$v){ 
  
//print_r($v);exit; 
echo '<div><p class="padding-left bg-eee st">'.strtoupper($k).'</p>'; 
for ($x=0; $x<count($v['title']); $x++) { 
             echo '<a href="'.$v[url][$x].'"><strong>'. $v[title][$x].'</strong></a><br/><hr/>'; 
              
        }     
             echo '<br/></div>';// print_r($b%4); 
             if($b%3==0){echo '<hr></hr>';//hr{background:#ddd;color:#ddd;clear:both;float:none;width:100%;height:1px;margin:10px 0;
             border:none;-moz-box-sizing:content-box;box-sizing:content-box;}hr.space{background:#fff;color:#fff;visibility:hidden;}hr的css,强制换行,防止错位 
             } 
             $b++; 
             } 
{/dede:php} 
</div> 
</div>
 

关键词:织梦,获得,首,字母,方法,并,实现,文章,列表,    标签:
    更多资讯请收藏关注 网站模板(www.1yc.cn)

dede织梦"关键字不能小于2个字节"解决办法织梦搜索老是显示关键词不能小于2个字节,这里哪里出现了问题了呢,于是在... 2021-07-22
调用{dede:likewords}为织梦添加相关搜索词经常看到一些大型的网站会设置相关搜索,即使访客搜索的内容在本站暂时没有... 2021-08-14
织梦DEDECMS 如何调用随机数织梦DEDECMS 如何调用随机数 。 好了,什么是随即数字,很简单了... 2021-08-14
dedecms列表页调用文章正文内容的方法本文实例讲述了dedecms列表页调用文章正文内容的方法。分享给大家供... 2021-07-30
织梦给文章添加缩略图提示select_images.php文件报错的具体处理方法很多站长朋友都是用织梦dedecms程序建站,AB 织梦模板 网也是一... 2021-07-30
当前栏目调用上级栏目名称的办法问题:网站需要在栏目列表页调用上级栏目的名称,也就是在列表模板调用当前... 2021-07-30
织梦CMS调用问答栏目文章到首页实现方法使用织梦CMS问答模块的站长还是挺多的,织梦问答系统高分悬赏问题,待解... 2021-07-27
Dedecms频道,列表页,内容页中调用全站最新文章的方法本文实例讲述了Dedecms频道,列表页,内容页中调用全站最新文章的方... 2021-07-30
dede调用其他栏目的文章或者缩略图列表且有分页效果的方法arclist调用不能设置pagesize的属性,从而不能给文章分页。... 2021-07-27
织梦dedecms编辑文章不更新时间的方法在修改文章的时候,发现织梦DEDECMS5.7这个版本存在一个问题,修... 2021-07-22
织梦dede上传图片提示缺少图像源文件地址dedecms织梦后台编辑器里上传图片提示缺少图像源文件地址 有以下原... 2021-07-22
织梦dedecms系统中英文网站之中英文搜索结果最近做的中英文版搜索时发现搜索不尽人意总是出现双语混搭模式:这样可以解... 2021-07-27
DEDECMS 提示信息!修改方法织梦版权希望大家加上,尊重织梦,支持织梦。 很多站长在用织梦DedeC... 2021-07-27
dedecms后台文本编辑器不显示或加截慢解决办法很久以前卖了一个站了,结果买站的朋友说后台编辑器不可用了,打开之后发现... 2021-07-22
dedecms织梦系统 {dede:list}列表按多种排序显示orderby=sortrank 文档排序方式 orderby=hot... 2021-07-27
织梦dede调用dede:sql,dede:php标签 调用文章的静态链接地址很多时候我们用织梦后台调用数据的时候,自带的标签很多时候都没办法调用我... 2021-07-27
Dedecms经验:教你如何根据不同区域IP跳转到相对应页面大家都熟知的百度、京东、团购等网站,都会根据用户所在城市来提示当地城市... 2021-08-14
织梦更新列表页函数function GetInnerText()报错怎么办小编使用织梦这款开源的CMS系统建站也好多年了,遇到的奇葩报错也是数不... 2021-08-14

线
咨询热线:
135-0038-3336
在线客服:
点击这里给我发消息
微信交流:
公司官网: www.1yc.cn