Support » Fixing WordPress » How do I show only excerpts in Twenty Seventeen theme?

  • I’m using Twenty Seventeen theme. I’ve set it to show latest posts on front page. And in the “For each article in a feed, show” section I’ve selected “Summary.”

    But it still shows the full post instead of post excerpts. How can I show the excerpts only? Please help me.

Viewing 9 replies - 1 through 9 (of 9 total)
  • “For each article in a feed, show” section I’ve selected “Summary.”

    That is not applicable here. It is meant for RSS feed.

    But it still shows the full post instead of post excerpts. How can I show the excerpts only?

    Whether the page shows full content or except, depends on 2 things:
    1. What is the except length defined in WordPress
    2. Whethere you have placed the <!–more–> tag in the post content at the correct place where you want to show “Read more” or “Continue reading”

    So if your content is 10 lines long, and you want to show only 2 lines in the except, then you have to place the <!–more–> tag after two lines.

    In this case your content should look like:

    Line 1
    Line 2
    <!--more-->
    Line 3
    Line 4
    Line 5
    Rinku Y

    (@rinkuyadav999)

    index.php and archive.php files use to display archives / post in loop, so:

    You can replace get_post_format() with ‘excerpt’ in file index.php Line 45

    also You can replace get_post_format() with ‘excerpt’ in file archive.php Line 40

    It will better you create child theme and make these changes otherwise your codes will removed when you will update theme. https://codex.wordpress.org/Child_Themes

    Looks like twentyseventeen theme is hard-coded to show the full content at all places including the archive pages. The only place where it shows the excerpt is the search results.

    So, the only solution would be to create child theme and make the changes suggested by @rinkuyadav999

    The code located at http://www.blogmynotes.com/display-post-excerpt-twenty-seventeen-wordpress-theme/ works well, though make sure you upload template-parts/post/content.php to your child theme – don’t overwrite the parent theme as the post I linked to suggests to do.

    Whilst it would be nice to have a theme setting for this, you can just use the <!–more–> tag as @shariqkhan2012 originally suggested (there is a button for it in the visual editor). I have tested that this does work.

    It will then cut-off the post at the point you specify for your categories, homepage, tag pages etc.

    @rinkuyadav999 Hi bro, I tried your suggestion, but it still didn’t work. Is there any other way? Thanks

    Rinku Y

    (@rinkuyadav999)

    Hi @madesoma

    Simply find:
    get_template_part( 'template-parts/post/content', get_post_format() );
    Replace with:
    get_template_part( 'template-parts/post/content', 'excerpt' );

    in index.php Line 45 and archive.php Line 40

    The solution from @rinkuyadav999 definitely works. I have just implemented it on my site. Thanks for the help.

    There are two ways I got this done (any of these will work):

    1.
    content.php is the file that controls this aspect, you should look to that file to change the_content to the_excerpt (for the right conditional tags).

    PS: If this affect the main post/page display, then you need a condition to be added, such as:

    if ( is_singular() ) {
            the_content();
       } else { the_excerpt(); }

    As you’ll have to change the theme’s code, make sure you’re working in a child theme.

    2.
    You can edit the theme OR the child theme functions.php file:

    /* Replace the content with excerpts on home page */
    add_filter( 'the_content', 'replace_content_with_excerpt', 100 );
    //http://wordpress.stackexchange.com/a/77947/25187
    
    /**
     * Return excerpt if we are not on a singular post view.
     *
     * @param  string $content
     * @return string
     */
    function 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;
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.