WordPress中修改默認摘要the_excerpt()的長度

在wp-includes目錄下找到formatting.php,裏面有這樣一個函數:

function wp_trim_excerpt($text) { 
    global $post; 
    if ( " == $text ) { 
        $text = get_the_content("); 
        $text = apply_filters('the_content', $text); 
        $text = str_replace(']]>', ']]>', $text); 
        $text = strip_tags($text); 
        $excerpt_length =55; 
        $words = explode(' ', $text, $excerpt_length + 1); 
        if (count($words) > $excerpt_length) { 
            array_pop($words); 
            array_push($words, '[...]'); 
            $text = implode(' ', $words); 
        } 
    } 
    return $text; 
}

將$excerpt_length =55改爲你需要截取的字數。

對於中文文章的WordPress

如果你使用了《中文 WordPress 工具箱》插件,則可以在/wp-content/plugins/mulberrykit.php中找到函數mul_excerpt ($excerpt):

function mul_excerpt ($excerpt) { 
     $myexcerpt = substr($excerpt,0,255); 
     return utf8_trim($myexcerpt) . '...'; 
}

將其中的255修改爲你想截取的字數。

轉載自仲子說 [ http://www.wangzhongyuan.com/ ] 
原文鏈接:http://www.wangzhongyuan.com/archives/379.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章