Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

is it possible to get wordpress on the posts page to do the following example.

the first three posts need to have a large image spanning the width of the title box and a longer excerpt.

the rest of the posts need to be thinner and a smaller featured image floated left.

How would I go about changing this in the template or loop?

share|improve this question

2 Answers 2

First, you need to filter excerpt_length.

Assuming you want your default excerpt length to be 50 words:

<?php
function wpse53485_filter_excerpt_length( $length ) {
    return 50;
}
add_filter( 'excerpt_length', 'wpse53485_filter_excerpt_length' );
?>

That will make all excerpts 50 words. Make sure that works first.

Then, add in an appropriate conditional, to use a different excerpt length for a static page for posts. Assuming you use a custom page template, named template-posts.php, you could filter specifically for that page template, using is_page_template().

Assuming you want the page for posts to use an excerpt length of 100 words:

<?php
function wpse53485_filter_excerpt_length( $length ) {
    if ( is_page_template( 'template-posts.php' ) ) {
        return 100;
    } else {
        return 50;
    }
}
add_filter( 'excerpt_length', 'wpse53485_filter_excerpt_length' );
?>

Using this approach, you can conditionally return any number of excerpt lengths based on various contexts.

share|improve this answer

Hard without having more info like how is your loop? Do you have two loops, one for the first 3 posts and a second for the rest ? Do you have one loop and assign a different markup with a counter ? Without having more info all that I can give to you to modify the excerpt is this:

Paste this on your functions.php file

function dp_clean($excerpt, $substr=0) {
    $string = strip_tags(str_replace('[...]', '...', $excerpt));
    if ($substr>0) {
        $string = substr($string, 0, $substr);
    }
    return $string;
}

And then use this <?php echo dp_clean($post->post_content, 250); ?>

change 250 to some value to suit your needs

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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