在侧边栏中显示文章摘录


Display a Post Excerpt in Sidebar?

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

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

我希望在侧边栏中,摘录的长度限制在20个字以内

可以使用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>