WordPress - 自定义the_excerpt()不起作用


Wordpress - customising the_excerpt() not working

我在我的函数.php脚本中添加了以下代码在我的主题中:

function custom_excerpt_length( $length ) {
    return 15;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function new_excerpt_more( $more ) {
    return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

如本页所示:http://codex.wordpress.org/Template_Tags/the_excerpt

但摘录的长度仍然是默认的 55 个单词,末尾的字符串仍然是[...]而不是...

WordPress版本是3.4.1

我用来显示摘录的代码很简单:

the_excerpt();

有没有人对如何修复它以使我的函数.php添加功能有任何想法?

使用此代码限制内容

<?php query_posts('cat=ID'.'&showposts=NO. OF POST') ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_post_thumbnail(); ?>
<p><?php echo substr(get_the_excerpt(), 0,65).' [...]'; ?></p>
<a href="<?php the_permalink(); ?>">Read More...</a>

<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>

我通过使用类似以下内容的东西设法实现了预期的结果:

$excerpt = get_the_excerpt();
$excerpt = preg_replace('/'s+?('S+)?$/', '', substr($excerpt, 0, 71));
echo '<div class="blog-posts-grid-box-excerpt">' . $excerpt . '...</div>';

希望这对发现这个问题的人有用。