我刚刚在中添加了一个静态页面选项Reading Settings 借助于this 邮递
如果front-page.php
存在,用于Homepage. 我应该如何命名模板文件,以确保无论页面名称如何,自定义静态页面始终使用该文件?
我刚刚在中添加了一个静态页面选项Reading Settings 借助于this 邮递
如果front-page.php
存在,用于Homepage. 我应该如何命名模板文件,以确保无论页面名称如何,自定义静态页面始终使用该文件?
模板层次结构仅涵盖列出的内容here. 因此,没有文件名,您可以为其提供一个模板,以便在默认情况下自动使用。
但是,可以使用page_template_hierarchy
钩因此,使用这个钩子,您可以检查当前正在查看的页面是否是设置为自定义静态页面的页面,如果是,请将您自己的模板名称添加到列表的顶部。
因此,在链接的接受答案中,静态页面保存为page_for_projects
, 这意味着代码如下所示:
function wpse_339118_projects_template_hierarchy( $templates ) {
$page_id = get_queried_object_id();
$page_for_projects = get_option( \'page_for_projects\' );
// If the current page is the Projects page.
if ( $page_id === $page_for_projects ) {
// Use projects.php as the template, if it exists.
array_unshift( $templates, \'projects.php\' );
}
return $templates;
}
add_filter( \'page_template_hierarchy\', \'wpse_339118_projects_template_hierarchy\' );
使用该代码,如果您命名模板projects.php
, 当查看保存为自定义静态页面的页面时,它将自动加载。所以,我在网上做了一些研究,但没有找到可靠的答案,所以我来了。我需要为特定类别创建自定义woocommerce类别页面。例如,我有一个类别叫做“Awesome”。而不是使用由短代码生成的常规类别页面[product_category category=\"something\"], 我想为自定义特定类别页面Awesome.我发现我需要编辑taxonomy-product_cat.php 但我不知道如何将其链接到名为awesome.换句话说,我正在考虑制作php文件的自定义副本,然后将其添加为主题templ