【问题标题】:Change the default template to a custom template将默认模板更改为自定义模板
【发布时间】:2018-02-01 10:46:30
【问题描述】:

我通过

创建了一个类似“页面”的管理菜单栏
register_post_type() 

并且红色表示在页面属性部分的自定义模板和默认模板之间切换的功能在 register_post_type() 中不可用。(图片)

有谁知道我需要在 php 文件本身中写什么,才能将默认模板更改为我想要的任何自定义模板?

Page Attributes

【问题讨论】:

  • 我是否正确假设您的意思是您希望自定义帖子类型中的页面模板功能?
  • 是的,但是根据 [Wordpress codex ](codex.wordpress.org/Function_Reference/add_post_type_support) "$supports = 'page-attributes' (模板和菜单顺序) (hierarchical must be true) (the page模板选择器仅适用于页面帖子类型)"

标签: php wordpress templates


【解决方案1】:

从 WordPress 4.7 开始,您可以在自定义帖子类型上使用页面模板功能。为此,您需要按如下方式修改模板注释。

/*
 * Template Name: Leaderhsip
 * Template Post Type: Staff
 */

这将为您提供一个默认的人员模板,该模板将使用 single-staff.php 文件或 single.php 或正常 WP 后备使用的任何内容。并且还为您提供了一个自定义模板,供您在此示例中选择领导角色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    相关资源
    最近更新 更多