Support » Fixing WordPress » Difficulty limiting post excerpts

  • Resolved Graycode


    Hi All,

    I have looked for a solution to my problem and although i have seen code such as adding this to functions.php:

    function limit_words($string, $word_limit) {
    	// creates an array of words from $string (this will be our excerpt)
    	// explode divides the excerpt up by using a space character
    	$words = explode(' ', $string);
    	// this next bit chops the $words array and sticks it back together
    	// starting at the first word '0' and ending at the $word_limit
    	// the $word_limit which is passed in the function will be the number
    	// of words we want to use
    	// implode glues the chopped up array back together using a space character
    if (count($words) > $word_limit ) {$end = '…';}
    return implode(' ', array_slice($words, 0, $word_limit)). $end;

    and this in my blog.php: ` <?php echo limit_words(get_the_excerpt(), ’10’); ?>
    The link is

    Help is much appreciated!


Viewing 15 replies - 1 through 15 (of 19 total)
  • I see a few ways that work on this thread.

    Thanks Aaron, I did see that but it seems to only take a snippet of the excerpt off. I wonder if it is the placement of the code but this is how the code looks after I’ve put it in.

    <div id="blogpage">
    	<?php query_posts('posts_per_page=2'); ?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="post-block-blog">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
           <p class="post-date"><?php the_time('j M Y'); ?></p>
            <?php the_content(); ?>
              $excerpt = get_the_excerpt();
              echo string_limit_words($excerpt,25);
          <p class="readmore"> <a href="<?php the_permalink(); ?>" title="Continue reading this article">Read more</a></p>
    		<?php endwhile; ?>

    I have even reduced and increased the number just to see where I could be going wrong… but still cant figure it out! :s

    What exactly are you trying to accomplish?

    I’m trying to accomplish having just a preview of my blog posts visible on the blog page.

    See this link-

    Right now, it’s displaying the entire blog post and I want it to show as above.

    This is how I always do it.


    <?php the_content(); ?>

    change to

    <?php the_excerpt(); ?>

    So to clarify, would you write it as the link demonstrates but just changing the above?

    I have an image in my content so would this be affected?

    Yes just change the word content to excerpt.

    You will not see the image in the excerpt. They would need to click through to the actual page/post to see it.

    Thank you. Yes, I changed it and although it looks good, that image needs to display as I showed in the link.

    I’d need it to show the image associated with the post and an excerpt underneath.

    Above the excerpt code add this.

    <?php if ( has_post_thumbnail() ) {
    } ?>

    Now go back in your post and on the right side set the Featured Image. What this code does is display whatever image is set as the Featured Image in the post.

    Awesome! Works brilliantly, thanks Aaron. 🙂

    Lastly, can I amend how much of that excerpt is displayed?

    Go in and edit your post and where you want it to cutoff put the below code.


    There is also a button for that code in the HTML editor.

    It works but not accurately.

    I used the Visual editor to place that code in but its like it cuts it off but adds the rest to the end lol.

    I’ve added several spaces where the space is meant to be so you can see what i mean.

    If its an unnecessary hassle, I can leave it but I’d like to be as accurate to that image i showed you as possible.

    You’ve been so helpful thank you.

    hey guys i ve been having difficulty to find the excerpt part because all i can find is ‘content’.
    IT changed really sudden when i changed the backround pic in simple catch theme and from full post it only shows an excerpt… i ve tried to find it but i cant… please help!!!

    oh the site is this if anyone would like to help me!


    You would need to start your own topic for what problems you are having, not jump in on someone elses.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Difficulty limiting post excerpts’ is closed to new replies.