我正在创建一个新闻稿网站,每个新闻稿登录页都使用与首页相同的模板。是否有强制每个新闻稿登录页使用首页模板的方法。
编辑编辑时事通讯时,可以在页面属性框中按模板名称选择模板,但我想知道是否有办法让这更简单。
提前谢谢。
我正在创建一个新闻稿网站,每个新闻稿登录页都使用与首页相同的模板。是否有强制每个新闻稿登录页使用首页模板的方法。
编辑编辑时事通讯时,可以在页面属性框中按模板名称选择模板,但我想知道是否有办法让这更简单。
提前谢谢。
如果您的新闻稿是自定义的帖子类型,您可以使用template hierarchy.
单个页面的模板为。。
single-{custom-post-type-name}.php
存档页的模板为。。archive-{custom-post-type-name}.php
这些模板会自动选中,您无需将它们添加到编辑器中的页面模板属性中。如果我正确理解了您的问题,下面的解决方案会将默认模板设置为您希望的php页面模板,但您需要查看主题文件中的文件名。您在标题中声明自定义帖子类型,但在您的问题中有页面,因此我根据页面进行了此操作,并对您可以将此更改为帖子/自定义帖子的位置进行了评论。
解决方案是定义默认页面模板,然后删除非管理员的“选择模板”选项,以确保其设置您可以删除第二个挂钩,以允许用户设置,前提是它只是将默认设置设置为您想要的。
// This hooks into the page template and over rides the default template use this to make sure your magazine template is always default
add_filter( \'template_include\', \'default_page_template\', 99 );
function default_page_template( $template ) {
// Change page to post if not a page your working on or custom post type name
if ( is_singular( \'page\' ) ) {
// change the default-page-template.php to your template name
$default_template = locate_template( array( \'default-page-template.php\' ) );
if ( \'\' != $default_template ) {
return $default_template ;
}
}
return $template;
}
// removes the user page select meta-box for user roles that are not admins
add_action( \'admin_menu\', \'restrict_access\' );
function restrict_access() {
// if the user is not admin - you can add any user roles or multiple roles
if(!current_user_can(\'administrator\')){
// Not tested but think this is the correct code for page template meta-box
remove_meta_box( \'pageparentdiv\', \'page\',\'normal\' );
}
}
所以,我在网上做了一些研究,但没有找到可靠的答案,所以我来了。我需要为特定类别创建自定义woocommerce类别页面。例如,我有一个类别叫做“Awesome”。而不是使用由短代码生成的常规类别页面[product_category category=\"something\"], 我想为自定义特定类别页面Awesome.我发现我需要编辑taxonomy-product_cat.php 但我不知道如何将其链接到名为awesome.换句话说,我正在考虑制作php文件的自定义副本,然后将其添加为主题templ