0

In my fresh WordPress installation I'm using a barebones child theme based on the twentyseventeen theme.

In Settings > Reading, "Your homepage displays" is set to the radio button "A static page", and I've duly selected a page for the "Homepage" and another page for the "Posts page".

The thing is, I'd like the second, the "Posts page", to show just excerpts, with the truncated text and the "continue reading" link to the actual post (as opposed to the full text of the post, which it's showing now), but I can't work out how to do it.

I get the impression that on some PHP script/page, to be duplicated and modified somewhere in my child theme, the_content should be changed to the_excerpt.

I don't know if that's right (maybe it's a bit more complicated), but even if it is right, I don't know which PHP script/page to look for.

Perhaps it may be relevant to say I'm using the classic editor (plugin).

Can anyone help?

1 Answer 1

0

I get the impression that on some PHP script/page, to be duplicated and modified somewhere in my child theme, the_content should be changed to the_excerpt.

This is correct.

You can refer to the Template Hierarchy to determine which template file your parent theme is using for the Posts page. Then you can copy that to your child theme and make the necessary function change there.

An issue you might run into is that the_content() might actually be being used in a template partial that's included by get_template_part(), rather than the main template directly. If that's the case then you can use the path passed to that function to find that template partial. Then you just need to copy that template into the child theme, in the sub subdirectories, and modify it there.

Another issue you might have is if there is a template partial, it might also be used for the full single post view. In that case you will need to copy both the main template, and the template partial, and then rename the template partial and change the reference to it in the main template file. That way you have a separate partial just for the posts page.

3
  • I had simply copied the template-parts folder from the "real" twentyseventeen theme to my child theme, and used trial and error to make that change of the_content to the_excerpt in the scripts in my child theme template-parts folder. So far I've found that, if I make that change in my child theme's template-parts > post > content.php (one instance to change), it evokes the excerpt in the post page but strangely in the actual post as well.
    – nev
    Commented Sep 17, 2021 at 17:16
  • Yes, that's what I described in my last paragraph. You will need to copy that file to something like template-parts > post > content-excerpt.php, and then copy index.php and change the reference to content to content-excerpt. Commented Sep 17, 2021 at 17:20
  • I did it. It wasn't as complicated in the end. It was template-parts/post/content.php that needed tweaking - under <div class="entry-content"> I had to introduce a conditional: if ( is_single() ) : the_content( sprintf( [etc] else: the_excerpt( sprintf( [etc]. Was tricky!
    – nev
    Commented Sep 17, 2021 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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