选择自定义帖子类型的模板菜单?
我在 WordPress 中创建了几个自定义帖子类型,并将 hierarchy 设置为 true,因此它的行为就像一个页面。
问题是,模板选择不可用。我已经应用了这个黑客 让菜单出现:
里面有一个文件meta-boxes.php WordPress 的 wp-admin\includes 安装..文件的第547行, 这是函数 page_attributes_meta_box() 只需添加 您的特定职位的支票 输入名称即可显示 模板页面下拉。
if (('page' == $post->post_type || 'yourcustomposttype' == $post->post_type) && 0 != count( get_page_templates() ) ) { $template = !empty($post->page_template) ? $post->page_template : false; ?>
这成功地使菜单出现,但数据不会保存。 “父”部分会保存,但“模板”不会保存。
有人有什么想法吗?
I have created a couple of custom post types in wordpress, and have set hierarchical to true so it behaves as a page.
The problem is, templates selection isn't available. I've applied this hack to get the menu to appear:
there is a file meta-boxes.php within
wp-admin\includes of the wordpress
installation.. line 547 of the file,
which is the function
page_attributes_meta_box() just add
the check for your particular post
type name to be able to display the
template pages drop down.if ( ('page' == $post->post_type || 'yourcustomposttype' == $post->post_type) && 0 != count( get_page_templates() ) ) { $template = !empty($post->page_template) ? $post->page_template : false; ?>
This successfully makes the menu appear, but the data won't save. The "parent" section saves but the "template" doesn't.
Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此功能自 4.7 起内置于核心中。启用应用程序自定义模板内的功能。例如,如果您有一个名为“Promotions”的模板,并且希望将其应用到您的 CPT“usa、uk、au”
WordPress 4.7 为所有帖子类型带来自定义页面模板功能
This feature is built into core since 4.7. Enable the functionality inside the applicate custom template. For example, if you have a template called "Promotions" and you want to apply it to your CPT "usa, uk, au"
WordPress 4.7 Brings Custom Page Template Functionality to All Post Types
我用过这个插件,发帖没问题,试试吧:)
https:// /wordpress.org/extend/plugins/custom-post-template/
I've used this plugin and it was ok for posts, try it :)
https://wordpress.org/extend/plugins/custom-post-template/
偶然发现这个问题寻找相同的功能。我知道这有点晚了,但我想我找到了解决方案。通过使用该插件查看自述文件,您可以将其添加到您正在寻找的功能的functions.php中。
Stumbled across this question looking for the same functionality. I know this is a little late but I think I found the solution. By looking into the readme file with the plugin you can add this to your functions.php for the functionality you're looking for.