实现自定义标记/纳税页面 时间:2015-10-12 作者:gravy 我的问题有几个方面:我当前的自定义主题相当普通,有主页、标签/税务索引页和内容页模板。我希望能够为标记页提供两个自定义布局模板,因此,我希望:检查此标记id/slug是否有自定义布局,如果有,请加载它及其自定义布局元素。如果没有,请加载默认模板。我的网站流量很大,因此我正在寻找一种性能开销不大的解决方案。理想情况下,在确定是否加载自定义内容时,我想知道Wordpress是否提供标签/税号或slug,以便我可以在自定义表上快速查找。 1 个回复 SO网友:Milo 您可以使用tag_template or taxonomy_template filters 并从中检查查询的对象,然后使用locate_template 获取模板路径。function wpd_tag_template_filter( $templates = \'\' ) { $this_tag = get_queried_object(); // check $this_tag->term_id, $this_tag->slug, etc. $templates = locate_template( \'my_custom_template.php\', false ); return $templates; } add_filter( \'tag_template\', \'wpd_tag_template_filter\' ); 文章导航