是否可以覆盖get_template_part()的结果?
我正在研究一个子主题,我强烈不希望覆盖主模板文件,以保持子主题的简单性,并尽可能减少代码量和维护时间。 在循环中,父主题中的index.php模板使用: get_template_part( 'content' ); 它将引入content.php,我希望它的行为更相似get_template_part( 'content', get_post_format() );或相似,以便引入不同的模板,例如content-aside.php等,而不在子主题中创建index.php来覆盖父级进行单行更改。 get_template_part() 由组成: function get_template_part( $slug, $name = null ) { do_action( "get_template_part_{$slug}", $slug, $name ); $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "{$slug}-{$name}.php"; $templates[] = "{$slug}.php"; locate_template($templates, true, false); } 所以有一个动作,在我的例子中叫做 get_template_part_content 我可以使用以下类似的动作: …