wordpress获取文章摘要的调用方法

<?php if (has_excerpt()) {
echo $description = get_the_excerpt(); //文章编辑中的摘要
}else {
echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 170,”……”); //文章编辑中若无摘要,自定截取文章内容字数做为摘要
} ?>
————————————————

设计实例:

<meta name="description" content="<?php
if(is_home()||is_category()||is_tag()){
    echo  iconv('GB2312','UTF-8','提供PDF杂志,图书免费下载,在线阅读.包括读者,时尚,美食,家居,财经,人物周刊等');
}
if(is_single()){
    if (has_excerpt()) {
        echo $description = get_the_excerpt();
    }else {
        function trimall($str)
        {
            $qian = array(" ","\t", "\n", "\r");
            return str_replace($qian, '', $str);
        }
$str = mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 500,'...');
        echo $description =trimall($str); }
}
?>
">

————————————————

相关文章:

php去除空格和换行:http://www.myit66.com/4121.html

 

————————————————
版权声明:本文为CSDN博主「pengxiao87」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/pengxiao87/article/details/86319969

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注