2014-05-13 64 views
0

我想從摘錄框中使用the_excerpt()。我有一個過濾器來控制應該出現的單詞數量。儘管如果摘錄是從內容區域獲得的,它將起作用,但如果它從帖子編輯器中的摘錄框中獲取,它將無法正常工作。截取Wordpress中摘錄框的摘錄

我想要麼 a:從內容區域摘錄,所以截斷工作正常。

OR

B:使用來自摘錄箱的摘錄,但能夠申請的截止。

function custom_excerpt_length() { 
global $myExcerptLength; 

if ($myExcerptLength) { 
    return $myExcerptLength; 
    } 
else { 
    return 25; //default value 
} 
} 
add_filter('excerpt_length', 'custom_excerpt_length'); 

在我的模板...

<div class="blog-post-excerpt"> 

<?php $myExcerptLength=30; 
     the_excerpt(); 
     $myExcerptLength=20; 
?> 

回答

0

我用我自己的解決辦法...

echo substr(strip_tags(get_the_content()),0,180).'...'; 

代替the_excerpt()