【问题标题】:create custom post type for category为类别创建自定义帖子类型
【发布时间】:2016-06-30 06:08:18
【问题描述】:

如何为像这个示例这样的类别创建自定义帖子类型。我将在输入框中输入文本并将其作为类别名称获取。

public function panotour_register_post_type(){
    register_post_type(self::$custom_post_type,array(
            'taxonomies' => array('category'),
            'name'         => 'CategoryName',
            'hierarchical' => true,
            'query_var' => true
        )
    );
}

【问题讨论】:

  • 您的意思是将自定义分类法转换为自定义帖子类型

标签: php wordpress categories


【解决方案1】:

创建自定义帖子类型并将该帖子类型添加到使用分类法的类别中,

function create_post_type() {
    $args = array(
        'label'               => __( 'cpost', 'twentythirteen' ),
        'description'         => __( 'Custom Post Type', 'twentythirteen' ),
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
        'taxonomies'          => array( 'category_name' ),
    );

    // Registering  Custom Post Type
    register_post_type('cpost', $args );

}

add_action( 'init', 'create_post_type', 0 );

【讨论】:

  • 非常感谢 php 用户,这很棒而且很完美,但我想要的只是作为类别名称的名称。比如我输入 school,apartment,mall 然后这个东西就会变成post的一个category。这可能吗?
猜你喜欢
  • 2020-06-06
  • 1970-01-01
  • 1970-01-01
  • 2020-11-01
  • 2020-01-19
  • 2016-05-13
  • 1970-01-01
  • 2011-06-24
  • 2013-05-12
相关资源
最近更新 更多