0

How to display excerpts in the homepage instead of full post automatically, without the need to insert <!--more--> in every post ?

I tried this plugin http://wordpress.org/extend/plugins/advanced-excerpt/ which or doesn't work or I can't use it.

Here's how I configure it http://wordpress.org/support/topic/plugin-advanced-excerpt-doesnt-work-installed-by-instructions-url-included?replies=1#post-2810718

This is my website.

I solved the problem using Michael's answer, which made my plugin work. http://wordpress.org/extend/plugins/advanced-excerpt/

1
  • To Michael: This worked great, but can you tell me where to go and do if I also want to have the categories with excerpts ? Could it be by adding " and category " to the script <?php if (is_search() || is_home() ) : // Only display Excerpts for Search and posts page?> " Thank you
    – user22718
    Commented Oct 20, 2012 at 19:07

2 Answers 2

4

general:

locate the template for the home page - often index.php - if not see http://codex.wordpress.org/Template_Hierarchy

find the_content() (possibly with some parameters in the brackets) and change that to the_excerpt() - http://codex.wordpress.org/Function_Reference/the_excerpt

specific for Twenty Eleven:

index.php points to the template part content.php; in content.php edit this line:

<?php if ( is_search() ) : // Only display Excerpts for Search ?>

change it to:

<?php if ( is_search() || is_home() ) : // Only display Excerpts for Search and posts page ?>

http://codex.wordpress.org/Conditional_Tags

3
  • Thanks, it worked.Any ideas how to make an excerpt longer and exclude images ? :)
    – Tomas
    Commented May 11, 2012 at 10:13
  • @Tomas excerpts don't contain images by default. What you want sounds more like a limited content - you could try something like this: bavotasan.com/2009/…
    – jammypeach
    Commented May 11, 2012 at 10:59
  • instructions how to change the excerpt length are included in codex.wordpress.org/Function_Reference/the_excerpt
    – Michael
    Commented May 11, 2012 at 13:18
0

Insert this into your functions.php file to control the length of the excerpt by characters NOT words

function the_content_limit($max_char, $more_link_text = 'Read more &raquo;', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = strip_tags($content);

   if (strlen($_GET['p']) > 0) {
      echo "<p>";
      echo $content;
      echo "&nbsp;<a href='";
      the_permalink();
      echo "'>".__("Read more")." &raquo;</a>";
      echo "</p>";
   }
   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo "<p>";
        echo $content;
        echo "...";
        echo "&nbsp;<a href='";
        the_permalink();
        echo "'>".$more_link_text."</a>";
        echo "</p>";
   }
   else {
      echo "<p>";
      echo $content;
      echo "&nbsp;<a href='";
      the_permalink();
      echo "'>".__("Read more")." &raquo;</a>";
      echo "</p>";
   }
}

Use it in your theme like this

<?php the_content_limit(245); ?>
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.