2013-04-14 166 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>'; 
    }