首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在wordpress中将页面属性添加到自定义帖子类型

在wordpress中将页面属性添加到自定义帖子类型
EN

Stack Overflow用户
提问于 2016-09-02 12:50:11
回答 2查看 6K关注 0票数 0

我已经为我的项目创建了自定义帖子类型,我想添加带有页面属性的自定义帖子类型。我已经用下面的代码做到了这一点:

代码语言:javascript
复制
function register_pt_boutique()
{
    register_post_type('boutique', array(
        'label'           => 'Boutiques',
        'description'     => 'This post type represents the featured items on the homepage.',
        'public'          => true,
        'show_ui'         => true,
        'show_in_menu'    => true,
        'capability_type' => 'post',
        'map_meta_cap'    => true,
        'hierarchical'    => true,
        // 'rewrite' => array('slug' => 'featured', 'hierarchical' => true, 'with_front' => false),
        'query_var'       => true,
        'has_archive'     => true,
        'menu_position'   => '7',
        'supports'        => array('title', 'page-attributes','thumbnail'),
        // 'taxonomies' => array('page-attributes'),
        'labels'          => array(
            'name'               => 'Boutiques',
            'singular_name'      => 'Boutique',
            'menu_name'          => 'Boutiques',
            'add_new'            => 'Add Boutique',
            'add_new_item'       => 'Add New Boutique',
            'edit'               => 'Edit',
            'edit_item'          => 'Edit Boutique',
            'new_item'           => 'New Boutique',
            'view'               => 'View Boutique',
            'view_item'          => 'View Boutique',
            'search_items'       => 'Search Boutique',
            'not_found'          => 'No Boutique',
            'not_found_in_trash' => 'No Boutique Found in Trash',
            'parent'             => 'Parent Boutique',
        )
    ));
}

使用此代码页属性选项时,管理员端有两个字段("parent“和"order"),但没有"template”字段选项。我想要具有“模板”字段的页面属性。

EN

回答 2

Stack Overflow用户

发布于 2020-05-14 00:59:01

正如您在页面模板文件中给出的模板名称一样:

代码语言:javascript
复制
Template Name: <template name>

您可以将自定义帖子类型指定为要显示的模板帖子类型

代码语言:javascript
复制
Template Post Type: <custom_post_type_1>, <custom_post_type_2>, <custom_post_type_3>

例如:我想要将页面属性添加到我的自定义帖子类型之一的项目组合中:

在我的页面模板中,我添加了:

代码语言:javascript
复制
Template Name: Portfolio Design
Template Post Type: portfolio

另外,别忘了在cpt注册过程中将‘page-attribute’添加到‘support’数组中:

代码语言:javascript
复制
'supports' => array(
            'custom-fields',
            'page-attributes'
        ), 

如果要更改标签“Page attributes”,则将其分配给“labels”数组中的“attributes”,即:

代码语言:javascript
复制
'labels' => array(
    'name' => 'Portfolios',
    'singular_name' => 'Portfolio',
    'attributes' => 'Page Attributes'
),

自定义帖子类型编辑器的仪表板截图如下:

票数 1
EN

Stack Overflow用户

发布于 2017-08-01 03:59:14

在WordPress4.7中,你可以直接从文件https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/中添加“模板”字段

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39284513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档