首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回指定字符数的摘录时出现问题

返回指定字符数的摘录时出现问题
EN

Stack Overflow用户
提问于 2011-06-12 02:42:47
回答 2查看 130关注 0票数 0

我使用以下代码获取一个字符串并返回特定数量的字符

代码语言:javascript
复制
<div class="top_posts">
<ul>';
}
elseif($i>1 && $i<=$number_of_posts) 
{
$retour.= "\n" . '<li>';
if($image_url) { $retour .= '<a href="' . get_permalink() . '"><img src="' . get_bloginfo('template_directory') . '/js/timthumb.php?src=' . $image_url . '&amp;h=120&amp;w=180&amp;zc=1" alt="" /></a>'; }
$retour .= '<h6><a href="' . get_permalink() . '">' . the_title("","",false) . '</a></h6>';
$retour.= get_wpe_excerpt('wpe_popular_posts');
$retour.='</li>';
if($i%2==1) 
$retour.= "\n" . '<li class="clear">&amp;</li>'; 
}
$i++;
endforeach;
$retour.='</ul></div>';
return $retour;
}
add_shortcode('popular-posts', 'popular_posts_code');

有争议的部分是这部分

$retour.= get_wpe_excerpt('wpe_popular_posts');

它会调用

代码语言:javascript
复制
function wpe_popular_posts($length) {
    return 55;
}

然而,我仍然没有修剪完整的文本字符串-感谢任何帮助。

//更新

get_wpe_excerpt函数如下所示

代码语言:javascript
复制
function get_wpe_excerpt($length_callback='', $more_callback='') {
    if(function_exists($length_callback)){
        add_filter('excerpt_length', $length_callback);
    }
    if(function_exists($more_callback)){
        add_filter('excerpt_more', $more_callback);
    }
    $output = get_the_excerpt();
    $output = apply_filters('wptexturize', $output);
    $output = apply_filters('convert_chars', $output);
    $output = '<p>'.$output.'</p>';
    return $output;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-12 07:55:52

现在确定get_wpe_excerpt()函数是如何完成的。您可能想尝试我在几个WordPress主题中使用的简单代码。

代码语言:javascript
复制
implode(' ', array_slice(explode(' ', get_the_content()), 0, 55));
票数 0
EN

Stack Overflow用户

发布于 2011-06-12 06:44:10

您想返回字符串的前55个字符吗?

试试substr($input, 0, 55);

然而,我真的不明白对$retour.= get_wpe_excerpt('wpe_popular_posts');的调用是怎么回事……所以也许我误解了你想要实现的目标?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6317811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档