doukong1391 2014-01-24 18:39
浏览 17
已采纳

在Wordpress的摘录结尾处有3个点

How to get ... (3 dots) at the end of the excerpt? I am using this function in my functions.php

function word_count($string, $limit) {
    $words = explode(' ', $string);
    return implode(' ', array_slice($words, 0, $limit));  
}

And echoing like this in my content.php:

echo word_count(get_the_excerpt(), '20');

I want 3 dots at the end of the excerpt. Please help. Thank you.

  • 写回答

3条回答 默认 最新

  • dsiuy42084 2014-01-24 18:45
    关注

    If your excerpts are always longer than 20 words, you can use the following to append ellipsis any time while truncate it with your word_count function

    echo sprintf("%s…", word_count(get_the_excerpt(), 20));
    

    If the excerpts might also be 20 words or shorter, you should also check for it's length

    the_excerpt_max_words(20);
    
    function the_excerpt_max_charlength($limit) {
    
        $words = explode(' ', get_the_excerpt() );
    
        //if excerpt has more than 20 words, truncate it and append ... 
        if( count($words) > 20 ){
            return sprintf("%s…", implode(' ', array_slice($words, 0, $limit)) );
        }
    
        //otherwise just put it back together and return it
        return implode(' ', $words);
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度