2

我已将以下代码添加到我的主题中的 functions.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();

有没有人对如何修复它有任何想法,以便我的 functions.php 的添加工作?

4

2 回答 2

5

使用此代码限制内容

<?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;?>
于 2012-09-03T07:54:18.540 回答
0

通过使用以下方式,我设法达到了预期的结果:

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

希望这对发现这个问题的人有所帮助。

于 2012-08-03T11:25:25.183 回答