Display a Post Excerpt in Sidebar?

I am working on redesigning my site and find myself needing to display post excerpts on my sidebar. the_excerpt() seemed like the right thing to use but I am also using excerpts on my main blog page. The 55 word limit looks good on my homepage but not my sidebar. I need a way to limit the words returned in the_excerpt ONLY in my sidebar.

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

I’d like for in the sidebar, the excerpt length to be limited to something like 20 words

Related posts

Leave a Reply

1 comment

  1. You can use 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>