function Limit_Char($max_char = 200, $more_text = '...', $more_link_text = '', $limit_type = 'content') {
if ($limit_type == 'title') { $limiter = get_the_title(); }
else { $limiter = get_the_content(); }
$limiter = apply_filters('the_content', $limiter);
$limiter = strip_tags(str_replace(']]>', ']]>', $limiter));
if (strlen($limiter) > $max_char) {
$limiter = substr($limiter, 0, $max_char+1);
$limiter = utf8_conver($limiter);
echo $limiter;
echo $more_text;
if ($more_link_text != '') {
echo ' <a href="';
echo the_permalink();
echo '">'.$more_link_text.'</a>';
}
} else {
echo $limiter;
}
}
function utf8_conver($str) {
$len = strlen($str);
for ($i=strlen($str)-1; $i>=0; $i-=1){
$hex .= ' '.ord($str[$i]);
$ch = ord($str[$i]);
if (($ch & 128)==0) return(substr($str,0,$i));
if (($ch & 192)==192) return(substr($str,0,$i));
}
return($str.$hex);
}
<?php Limit_Char(200); ?>
<!-- 200是你需求截断多少字节的长度,依据实际状况修正。-->
以上就是安达网络工作室关于《wordpress中文截断产生乱码解决方法》的一些看法。更多内容请查看本栏目更多内容!
关于日拜访量还不错的WordPress网站来说,一定都会存在很多待审核的渣滓评论,假如要经过WP后盾删除,那几乎...
插件制造预备工作 首先咱们在\wp-content\plugins目录下增加一个文件夹叫做”My-Mood”,在文件夹中增加一个...
1、修正文章页面模板single.php关上模版文件中的single.php,在其中搜寻在这行上面加上:复制代码代码如下:...
本文实例讲述了WordPress给文章图片主动增加链接的办法。分享给大家供大家参考。详细剖析如下: 咱们会看到...
代码如下:<?php/*在根目录 -> wp-content -> themes 下创立mytheme文件夹用来寄存创立新主题模板 在mythem...
1.增加性能 在function.php中拔出代码 add_theme_support('post-thumbnails'); 拔出之后会在后盾编辑文章的...