您当前的位置: 主页 > 优化教程
方法一,织梦默认有这个函数,在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)

织梦DEDECMS内容页调用当前栏目名称的标签其中 {dede:field function=GetTypeName... 2021-07-22
织梦选择特定的栏目搜索技巧针对企业网站,特别是很多产品类别的企业网站,需要对栏目类别进行选项搜索... 2021-07-27
dedecms不同栏目调用不同的广告代码dedecms不同栏目调用不同的广告代码 在制作dedecms模板的时... 2021-07-30
dedecms各模板调用自定义字段的方法本文实例讲述了dedecms各模板调用自定义字段的方法。分享给大家供大... 2021-07-30
DEDECMS“提交表单同系统配置不相符,请重新提交!”的解决方法解决会员中心编辑文章是出现的提交表单同系统配置不相符,请重新提交提示:... 2021-08-09
织梦织梦后台怎么增加栏目上传缩略图功能我们用织梦制作企业网站时,因为有很多的栏目,每个栏目的图片都不一样,单... 2021-08-14
实现DedeCms织梦模板文章标题分栏显示的教程代码如下: {dede:field name=title/}-{ded... 2021-07-22
Dede 删除文档同时文章中的图片的方法首先,在/include目录下建立extend.func.php文件.... 2021-07-30
织梦直接获取上一篇下一篇的URL网址链接方法织梦dedecms的上一篇、下一篇调用一般在文章页里面是用{dede:... 2021-07-22
织梦标签把","逗号改成空格技巧DedeCms是现在非常流行的建站系统,因为其实容易入门,尤其对于广大... 2021-08-14
织梦DEDECMS整站动态化或整站静态化设置方法简单说下的是,网站空间小而数据库还可以的话,使用动态浏览也是不错的,但... 2021-07-22
针对织梦程序列表字段内可有可无的显示方法这个方法就和Dedecms的文章列表没有缩略图的不显示图片,如果有缩略... 2021-08-14
DEDE织梦文章和列表页均使用拼音,使之更适合于SEO的解决方案一、DEDE 修改默认文章命名规则 1、单独添加分类默认修改,修改文件... 2021-07-27
织梦百度编辑器提交数据时如何防止html标签被转义第一种方式:好用 $str = lt;pgt;amp;nbsp;amp... 2021-07-22
织梦Dedecms首页调用自定义内容模型方法首页调用自定义字段 如何在首页调用自定义内容模型的内容呢 需要在arc... 2021-07-27
dedecms文章页上一篇与下一篇标题长度截取的方法本文实例讲述了dedecms文章页上一篇与下一篇标题长度截取的方法。分... 2021-07-30

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