简体   繁体   English

自定义类别上的WordPress自定义帖子类型

[英]WordPress Custom Post Types on Custom Categories

Can some one let me know how I can create custom Category and Post type including the items in side the red box and add them to WordPress dashboard? 可以让我知道如何创建自定义类别和帖子类型,包括红框旁边的项目并将其添加到WordPress仪表板吗?

在此处输入图片说明

Long explanation 详细说明

Below an example code: 下面是一个示例代码:

add_action('init', 'demo_register_post_type');

function demo_register_post_type() {
register_post_type('demo', array(
'labels' => array(
'name' => 'Demos',
'singular_name' => 'Demo',
'add_new' => 'Add new demo',
'edit_item' => 'Edit demo',
'new_item' => 'New demo',
'view_item' => 'View demo',
'search_items' => 'Search demos',
'not_found' => 'No demos found',
'not_found_in_trash' => 'No demos found in Trash'
),
'public' => true,
'supports' => array(
'title',
'excerpt'
),
'taxonomies' => array('category', 'post_tag')
));
}

And for the categories: 对于类别:

add_action('init', 'demo_add_default_boxes');

function demo_add_default_boxes() {
register_taxonomy_for_object_type('category', 'demo');
register_taxonomy_for_object_type('post_tag', 'demo');
}

Of course, you can customize it, instead of "demo" having something else. 当然,您可以自定义它,而不用“演示”包含其他内容。


Short explanation 简短说明

You need to add 'taxonomies' => array('category') in your register_post_type() function. 您需要在register_post_type()函数中添加'taxonomies'=> array('category')

Let us know please. 让我们知道。

To register a new custom post type, use the register_post_type function. 要注册新的自定义帖子类型,请使用register_post_type函数。

To add a custom category, use the register_taxonomy function. 要添加自定义类别,请使用register_taxonomy函数。

Once you add these, they'll automatically show up in your dashboard. 添加这些内容后,它们会自动显示在您的信息中心中。

To show a custom category you added with register_taxonomy function you should set "show_admin_column" parameter to true (it's false by default) 要显示使用register_taxonomy函数添加的自定义类别,应将“ show_admin_column”参数设置为true (默认情况下为false)

eg. 例如。

register_taxonomy('event_category', array('event'), array(
  'public' => true,
  'show_in_nav_menus' => true,
  'hierarchical' => true,
  'show_ui' => true,
  'query_var' => true,
  'show_admin_column' => true
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM