2012-08-03 73 views
2

我加入以下代码到我的functions.php脚本我的主题范围内:WordPress的 - 自定义the_excerpt()不工作

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工作?

回答

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;?> 
+0

工程与WordPress 3.1了。谢谢! – deathlock 2012-09-25 16:23:40

0

我已经成功使用的线沿线的东西,达到预期的效果:

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

希望这是一些使用的人谁发现这个问题。