2013-04-14 165 views
0

我的wordpress主題目前在摘錄的末尾添加了「...」。要閱讀整篇文章,您必須點擊精選圖片或帖子標題。需要幫助修改摘錄代碼

我想用「......閱讀更多」替換「...」,並且喜歡這篇文章。

我的博客位於@ www.cur-mudg-eon.com,如果您需要了解它是如何設置的。

theme-function.php中的代碼全部位於pastebin

這裏的代碼位,我認爲需要改變:

<?php 

// The excerpt based on words 
function my_string_limit_words($string, $word_limit) 
{ 
    $words = explode(' ', $string, ($word_limit + 1)); 
    if(count($words) > $word_limit) 
    array_pop($words); 
    return implode(' ', $words).'...'; 
} 

// The excerpt based on character 
function my_string_limit_char($excerpt, $substr=0) 
{ 

$string = strip_tags(str_replace('...', '...', $excerpt)); 
if ($substr>0) { 
    $string = substr($string, 0, $substr); 
} 
return $string; 
    } 

如果需要更多的信息/代碼回答我的問題讓我知道。

感謝

回答

1

codex

function new_excerpt_more($more) { 
    return ' <a class="read-more" href="'. get_permalink(get_the_ID()) . '">...Read More</a>'; 
} 
add_filter('excerpt_more', 'new_excerpt_more'); 
+0

謝謝Obmerk。我是否使用此代碼替換我提供的代碼的一部分,或者只是將它添加到現有代碼中? – BryGuy

+0

把它放在你的function.php文件中 –

+0

當我將代碼添加到「function.php」文件時,它會導致以下錯誤:「內部服務器錯誤 服務器遇到內部錯誤或配置錯誤,無法完成請求。 「 – BryGuy

0

下面是代碼,我改變了部分:

// The excerpt based on words 
function my_string_limit_words($string, $word_limit) 
{ 
    $words = explode(' ', $string, ($word_limit + 1)); 
    if(count($words) > $word_limit) 
    array_pop($words); 
    return implode(' ', $words).'...'; 
} 

我只不過是取代了 「...」 下面的代碼:

<a class="read-more" href="'. get_permalink(get_the_ID()) . '">...Read More</a> 

這是最終代碼的樣子:

// The excerpt based on words 
function my_string_limit_words($string, $word_limit) 
{ 
    $words = explode(' ', $string, ($word_limit + 1)); 
    if(count($words) > $word_limit) 
    array_pop($words); 
    return implode(' ', $words).'<a class="read-more" href="'. get_permalink(get_the_ID()) . '">...Read More</a>'; 
    }