【发布时间】:2013-04-17 13:57:41
【问题描述】:
我需要修改 Wordpress 插件(付费会员专业版)显示摘录的方式,这实际上已成为一个两部分的问题。
第一部分:有人可以指出正确修改插件的信息方向吗?有没有类似于你可以在核心上使用的钩子/过滤器的东西?
有趣的部分:
我想修改这段代码以确保只显示 1 段,无论其长度如何。如果段落少于 55 个字符,则显示整个内容,仅此而已。如果超过 55 个字符,则仅显示这 55 个字符。
这是插件的代码:
//if show excerpts is set, return just the excerpt
if(pmpro_getOption("showexcerpts"))
{
//show excerpt
global $post;
if($post->post_excerpt)
{
//defined exerpt
$content = wpautop($post->post_excerpt);
}
elseif(strpos($content, "<span id=\"more-" . $post->ID . "\"></span>") !== false)
{
//more tag
$pos = strpos($content, "<span id=\"more-" . $post->ID . "\"></span>");
$content = wpautop(substr($content, 0, $pos));
}
elseif(strpos($content, 'class="more-link">') !== false)
{
//more link
$content = preg_replace("/\<a.*class\=\"more\-link\".*\>.*\<\/a\>/", "", $content);
}
else
{
//auto generated excerpt. pulled from wp_trim_excerpt
$content = strip_shortcodes( $content );
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content);
$excerpt_length = apply_filters('excerpt_length', 55);
$words = preg_split("/[\n\r\t ]+/", $content, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$content = implode(' ', $words);
$content = $content . "... ";
} else {
$content = implode(' ', $words) . "... ";
}
$content = wpautop($content);
}
}
谢谢!
【问题讨论】: