如何添加支持以在帖子中添加标签。我尝试了一切,但仍然没有看到/显示后标签选项。
register_post_type( 'articles',
array(
'labels' => array(
'name' => __( 'Articles' ),
'singular_name' => __( 'Articles' )
),
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'excerpt','page-attributes','post-formats','custom-field' ),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'articles'),
)
);
答案 0 :(得分:1)
在此代码中,您可以使用自定义标记选项获取自定义帖子类型。
试试这段代码,
//* Create Custom Post Type
add_action( 'init', 'add_custom_post_type' );
function add_custom_post_type() {
register_post_type( 'members',
array(
'labels' => array(
'name' => __( 'Members', 'wpsites' ),
'singular_name' => __( 'Member', 'wpsites' ),
),
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-admin-users',
'public' => true,
'rewrite' => array( 'slug' => 'members', 'with_front' => false ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'member-type' ),
'menu_position' => 2,
));
}
add_action( 'init', 'create_custom_tag' );
function create_custom_tag() {
register_taxonomy(
'tag',
'members',
array(
'label' => __( 'Tag' ),
'rewrite' => array( 'slug' => 'tag' ),
'hierarchical' => true,
)
);
}
它适用于你
答案 1 :(得分:0)
您需要将post_tag分类法添加到注册函数中:
register_post_type( 'articles',
array(
'labels' => array(
'name' => __( 'Articles' ),
'singular_name' => __( 'Articles' )
),
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'excerpt','page-attributes','post-formats','custom-field' ),
'taxonomies'=>array('post_tag'),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'articles'),
)
);