nev
nev

Reputation: 233

Customising search results in twentyseventeen using content-search.php

Using a child theme based on the twentyseventeen theme, I customised

theme/template-parts/content.php

My modification changes the way the main posts page presents the list of blogposts.

However, I'd like this change to be reflected in search results, too, but I'm not sure how to.

The file search.php tells me to customise results content by creating a content-search.php file, which I think should reside in theme/template-parts/content-search.php.

I tried copying the contents of theme/template-parts/content.php and placing that in a file at theme/template-parts/content-search.php, but tinkering with minor adjustments to that file seem to show no difference to my search results.

So how do I customize search results content in my twentyseventeen child theme?

Upvotes: 2

Views: 653

Answers (1)

FluffyKitten
FluffyKitten

Reputation: 14312

You are almost there. Your own file should be in the /template-parts/posts/ folder of your theme. That's where get_template_part is looking for it:

get_template_part( 'template-parts/post/content', 'excerpt' );


As for what to call the file:

The comments in the theme's search.php say to use "content-search.php" but that file isn't used in twentyseventeen. I think this comment must be left over from previous incarnations of the themes (e.g. twentyfifteen does use content-search.php to display the search results) and is possibly wrong.

The file that is currently used to display the results is
twentyseventeen/template-parts/post/content-excerpt.php

We can tell this because the second parameter passed into get_template_part (i.e. "excerpt" in this case) is tells WP to look for the "content" file with "-excerpt" appended to the name, and if it doesn't find that then use the standard "content.php".

Therefore what you actually need to do is create your own results display in a file called

/your-theme/template-parts/posts/content-excerpt.php

... and not content-search.php like the comments say!

Upvotes: 1

Related Questions