2012-11-05 85 views
1

再次,我的熟練php技能讓我被它的字符串固定下來!兒童主題摘錄長度

我想在我的WordPress博客頁面上更改帖子摘要的摘錄長度。到目前爲止,我已經創建了一個子主題,取代了content.php文件代碼

<div class="entry-content"> 
      <?php the_excerpt(__('Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven')); ?> 
      <?php wp_link_pages(array('before' => '<div class="page-link"><span>' . __('Pages:', 'twentyeleven') . '</span>', 'after' => '</div>')); ?> 
     </div><!-- .entry-content --> 

,並增加了一個功能,用下面的代碼

<?php 

function CHILDTHEME_excerpt_length($length) { 
    return 600; 
} 
add_filter('excerpt_length', 'CHILDTHEME_excerpt_length'); ?> 

,什麼你知道文件.....它仍然保持和以前一樣的博客頁面長度。我究竟做錯了什麼?

所有幫助是非常讚賞一如既往

回答

1

必須設置過濾器優先權:

add_filter('excerpt_length', 'CHILDTHEME_excerpt_length', 999); 

不指定此功能的優先級WordPress的過濾器將在最後一次運行並覆蓋你在這裏設置。

0

您可能有一個過濾器在您的身後運行並重置了長度。你可以設置更高的優先級,這可以猜測,直到你足夠高。另一種選擇是刪除所有現有的過濾器爲您的添加你的這個鉤子之前:

function my_excerpt_length($length){ 
    return 400; 
} 
remove_all_filters('excerpt_length'); 
add_filter('excerpt_length', 'my_excerpt_length', 999); 
+0

這仍然是行不通的,我需要做一些content.php文件代碼? – Woolley

+0

糟糕,嘗試將999優先級添加到過濾器。你不需要改變'content.php',因爲它使用'the_excerpt()'來處理過濾器。 – doublesharp

+0

<?php remove_filter('excerpt_length','twentyeleven_excerpt_length'); add_filter('excerpt_length','new_excerpt_length',999); function new_excerpt_length($ length){ return 1020; } ?> – Woolley