使用 register_post_type 时显示类别和标签
show category and tags when using register_post_type
所以我用 register_post_type 添加书籍 post_type 部分。
但我想在后面板上显示类别和标签(以及更多)edit.php。
我知道如何在常规 post 中做到这一点(添加自定义字段)。
add_action( 'init', 'bookworm_blog_cpt' );
function bookworm_blog_cpt() {
register_post_type( 'book', array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book',
),
'description' => 'Books which we will be discussing on this blog.',
'public' => true,
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields' )
));
}
图片说明:
我在网上搜索了解决方案,但没有找到。
您需要使用挂钩将自定义列添加到 post 类型索引,您需要使用 3 或 4 个挂钩,因此 post 在这里举一个例子会有点冗长可能更令人困惑。
本文涵盖的主题:http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types
如果您不想使用该教程,您可以 Google 'add custom column to custom post type index',您将有很多选择。希望这能帮助您走上正确的道路。
所以我用 register_post_type 添加书籍 post_type 部分。
但我想在后面板上显示类别和标签(以及更多)edit.php。
我知道如何在常规 post 中做到这一点(添加自定义字段)。
add_action( 'init', 'bookworm_blog_cpt' );
function bookworm_blog_cpt() {
register_post_type( 'book', array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book',
),
'description' => 'Books which we will be discussing on this blog.',
'public' => true,
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields' )
));
}
图片说明:
您需要使用挂钩将自定义列添加到 post 类型索引,您需要使用 3 或 4 个挂钩,因此 post 在这里举一个例子会有点冗长可能更令人困惑。
本文涵盖的主题:http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types
如果您不想使用该教程,您可以 Google 'add custom column to custom post type index',您将有很多选择。希望这能帮助您走上正确的道路。