使用content-search.php定制2017年的搜索结果

使用content-search.php定制2017年的搜索结果,php,wordpress,Php,Wordpress,使用基于217主题的子主题,我定制了 theme/template parts/content.php 我的修改改变了主帖子页面显示博客帖子列表的方式 然而,我也希望这一变化能反映在搜索结果中,但我不知道如何做到 文件search.php告诉我通过创建content search.php文件来定制结果内容,我认为该文件应该位于theme/template parts/content search.php中 我试图复制theme/template parts/content.php的内容,并将其放

使用基于217主题的子主题,我定制了

theme/template parts/content.php

我的修改改变了主帖子页面显示博客帖子列表的方式

然而,我也希望这一变化能反映在搜索结果中,但我不知道如何做到

文件
search.php
告诉我通过创建
content search.php
文件来定制结果内容,我认为该文件应该位于
theme/template parts/content search.php

我试图复制
theme/template parts/content.php
的内容,并将其放在
theme/template parts/content search.php
的一个文件中,但对该文件稍作调整似乎对我的搜索结果没有任何影响


那么,如何在我的217个孩子主题中自定义搜索结果内容呢?

你就快到了。您自己的文件应该在 /模板部分/发布主题的文件夹。这就是
get\u template\u part
寻找它的地方:

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

至于如何调用该文件:

主题的search.php中的注释说要使用“content search.php”,但该文件在TwentySeven中没有使用。我认为这个评论一定是以前版本的主题留下的(例如,Twentytent确实使用content-search.php来显示搜索结果),可能是错误的

当前用于显示结果的文件是
twentyeven/template parts/post/content extract.php

我们可以这样说,因为传递到
get_template_part
(即本例中的“摘录”)的第二个参数告诉WP查找名称后面附加“-extract”的“内容”文件,如果找不到,则使用标准的“content.php”

因此,您实际上需要做的是创建自己的结果,并将其显示在名为

/your theme/template parts/posts/content extract.php


。。。而不是像评论所说的content-search.php

对不起,我的意思是
/template parts/**posts**/
-我遗漏了“posts”目录,但我的文件在那里。但是我可以用
content-extract.php
的副本而不是
content.php
进行实验,看看这是否会有所不同,反正我认为我走错了方向。我对
content.php
所做的更改出现在它的
entry content
div中,但该div没有出现在
content extract
@nev它被卡在我的答案的末尾,因此您可能错过了它,但是您还需要将“search”传递到
get_template_(摘录
部分@nev我不知道当他们说要创建一个名为“content search.php”的文件时,这些评论到底是什么意思。。。我想知道这是旧主题的遗留问题。实际上,您需要做的是在名为content-execrpt.php的文件中创建自己的结果显示。我会更新我的答案!