我使用以下代码获取一个字符串并返回特定数量的字符
<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 . '&h=120&w=180&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">&</li>';
}
$i++;
endforeach;
$retour.='</ul></div>';
return $retour;
}
add_shortcode('popular-posts', 'popular_posts_code');有争议的部分是这部分
$retour.= get_wpe_excerpt('wpe_popular_posts');
它会调用
function wpe_popular_posts($length) {
return 55;
}然而,我仍然没有修剪完整的文本字符串-感谢任何帮助。
//更新
get_wpe_excerpt函数如下所示
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;
}发布于 2011-06-12 07:55:52
现在确定get_wpe_excerpt()函数是如何完成的。您可能想尝试我在几个WordPress主题中使用的简单代码。
implode(' ', array_slice(explode(' ', get_the_content()), 0, 55));发布于 2011-06-12 06:44:10
您想返回字符串的前55个字符吗?
试试substr($input, 0, 55);
然而,我真的不明白对$retour.= get_wpe_excerpt('wpe_popular_posts');的调用是怎么回事……所以也许我误解了你想要实现的目标?
https://stackoverflow.com/questions/6317811
复制相似问题