2011-12-26 165 views
1

我正在重新设计我的网站,并发现自己需要在侧边栏上显示帖子摘录。 the_excerpt()似乎是正确的使用,但我也在我的主博客页面上使用摘录。 55个字的限制在我的主页上看起来不错,但不是我的侧边栏。我需要一种方法来限制仅在我的侧边栏中在the_excerpt中返回的单词。在侧栏显示帖子摘录?

<div id="sidebar"> 
    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title(); ?>"> 
     <?php the_title() ?> 
    </a> 
    <?php the_excerpt(); ?> 
</div> 

我想在侧边栏,摘录长度被限制到类似20个字

+0

试试这个 - > HTTP:/ /wordpress.org/extend/plugins/content-and-excerpt-word-limit/ – Rikesh 2011-12-26 05:11:02

回答

0

您可以使用SUBSTR()

<div id="sidebar"> 
    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title(); ?>"> 
     <?php the_title() ?> 
    </a> 
    <?php $mycontent=get_the_excerpt(); 
     echo substr($mycontent,0,20); 
    ?> 
</div> 
相关问题