需要帮助修改摘录代码

时间:2013-04-14 00:58:16

标签: php wordpress

我的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;
    }

如果需要更多信息/代码来回答我的问题,请告诉我。

由于

2 个答案:

答案 0 :(得分: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' );

答案 1 :(得分: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>';
  }