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.

My theme shows full posts on the main page and I want it to show only the summary, I tried searching for the_content tag in my theme's index.php file but it is not even there!
I don't have a home.php or category.php. I tried searching my whole wordpress installation for the_content and the only places i could find it is in page.php and even when changing it there it doesn't really work.

The other places I found it in my theme formats (image.php, audio.php...) but changing it there makes the post shows the summary even when you click on it and go inside the post.

My index.php file has this :

<?php if (have_posts()) : while (have_posts()) : the_post(); $format = get_post_format();  ?>

  <?php if($format == ''): ?>

    <?php get_template_part('library/functions/theme/formats/standar'); ?>


  <?php else: ?>

    <?php get_template_part('library/functions/theme/formats/'.$format); ?>

  <?php endif; ?>

<?php endwhile ?>

Do I need to do something specific there to make this work?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Decide about the_excerpt() or the_content() with a conditional: is_singular().

You can use a plugin and filter the_content depending on the current page’s type: archive or singular. But you can use it in your theme too.

add_filter( 'the_content', 't5_replace_content_with_excerpt', 100 );

/**
 * Return excerpt if we are not on a singular post view.
 *
 * @param  string $content
 * @return string
 */
function t5_replace_content_with_excerpt( $content )
{
    if ( is_singular() )
    {
        return $content;
    }
    // remove our filter temporarily.
    // Otherwise we run into a infinite loop in wp_trim_excerpt().
    remove_filter( 'the_content', __FUNCTION__, 100 );
    $excerpt = apply_filters( 'the_excerpt', get_the_excerpt() );
    add_filter( 'the_content', __FUNCTION__, 100 );
    return $excerpt;
}

In your theme find the line where you are calling the_content(). Change it to:

is_singular() ? the_content() : the_excerpt();
share|improve this answer
    
Can you please tell me how to add that to my theme? Is it in the index file?? –  unknownsolo Jan 2 '13 at 7:53
    
@user1231517 See my update. –  toscho Jan 2 '13 at 7:57
    
Do i also need to add that whole if statement somewhere or just replace the_content with your update?! –  unknownsolo Jan 2 '13 at 8:01
    
Just replace the one line. My plugin code is for themes you can not edit like Twenty Eleven. –  toscho Jan 2 '13 at 8:02
3  
Wow, thank you for the speedy replies, i will totally try this and let you know first thing in the morning, i am in bed now posting from my phone ;) –  unknownsolo Jan 2 '13 at 8:04

What theme are you working with?

This bit of code here:

<?php get_template_part('library/functions/theme/formats/standar'); ?>

Seems to suggest that your index.php is calling an template include. If you find the correct file (most likely located in that formats/standar directory) and replace the spot where the_content() appears with the the_excerpt(), you should see the summaries loading instead of the full content. This is going to modify a core theme file which is not recommended, so without knowing more about your theme and whether or not this is overridable I would say do it at your own risk.

share|improve this answer
    
It is a custom theme, inside the formats folder, i have standard.php, image.php, audio.php....when i open standard.php file and change the_content it does change on the front page but also when i click on the title to go inside the post, it still shows the summary only there!!! –  unknownsolo Jan 2 '13 at 7:56

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.