Forums

[resolved] Post excerpt options? (7 posts)

  1. fredhead
    Member
    Posted 1 year ago #

    Hi,

    This is my third, final for now, quick question. I've searched WP and Google to no avail:

    Is there a plugin or template tag that'll let me grab only the first n words of a post for display on the home page?

    I've imported hundreds of my posts from Moveable Type and going back 20 posts to create excerpts with the <!--more--> tag will be a bit of work. I'm looking for a template tag that'll just display a user-specified number of words in the post.

    I see that the Revolution template includes a plug-in, apparently, that limits content. I could not find a plugin in the WP list, or through Google.

    Any ideas, pointers, would be welcome. Thank you!

  2. ronchicago
    Member
    Posted 1 year ago #

    you might find something here...

    http://robsnotebook.com/the-excerpt-reloaded

  3. LenK
    Member
    Posted 1 year ago #

    Plugins are the easiest. A second way is to stick this in your theme's function.php file...

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'custom_trim_excerpt');
    
    function custom_trim_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $text = strip_tags($text);
    $excerpt_length = x;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words) > $excerpt_length) {
    array_pop($words);
    array_push($words, '...');
    $text = implode(' ', $words);
    }
    }
    return $text;
    }

    A third option is to use the Excerpt box directly beneath the Write Post window. It will display whatever you type in the input field.

  4. fredhead
    Member
    Posted 1 year ago #

    Thanks, Len! Any specific plugins to do this chore? Appreciate the code, at least.

  5. LenK
    Member
    Posted 1 year ago #

    Yes, ronchicago just posted a link to one such plugin. There maybe more in the Plugin Directory - I don't know as I didn't look.

  6. fredhead
    Member
    Posted 1 year ago #

    Thanks again, Ron, Len, this post can be marked as resolved.

  7. fredhead
    Member
    Posted 1 year ago #

    For people who might find this topic, there also appears to be another plugin, which I found through one of my clients' install, called Limit Posts. The URL is here:

    http://labitacora.net/comunBlog/limit-post.phps

    I find the Limit Posts plugin easier for my needs, but both it and the The Excerpt Reloaded plugins work fine.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.