Question

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?

Was it helpful?

Solution

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();

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top