如何更改“添加新帖子”以反映我的自定义帖子类型的名称?我要在以下代码中添加一些内容吗?我知道可以做到的...
function create_post_type() {
register_post_type( 'venues',
array(
'labels' => array(
'name' => __( 'Venues' ),
'singular_name' => __( 'Venue' )
),
);
答案 0 :(得分:1)
在标签数组中添加:
'add_new' => _x( 'Add New', 'venue', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Venue', 'your-plugin-textdomain' ),
也请阅读WordPress代码: https://codex.wordpress.org/Function_Reference/register_post_type
答案 1 :(得分:0)
您可以使用下面的代码来获得预期的结果。
<?php
$labels = array(
'name' => _x( 'Venues', 'Post Type General Name', 'text-domain' ),
'singular_name' => _x( 'Venue', 'Post Type Singular Name', 'text-domain' ),
'menu_name' => esc_html__( 'Venues', 'text-domain' ),
'parent_item_colon' => esc_html__( 'Parent Venues', 'text-domain' ),
'all_items' => esc_html__( 'All Venues', 'text-domain' ),
'view_item' => esc_html__( 'View Venues', 'text-domain' ),
'add_new_item' => esc_html__( 'Add New Venues', 'text-domain' ),
'add_new' => esc_html__( 'Add New', 'text-domain' ),
'edit_item' => esc_html__( 'Edit Venues', 'text-domain' ),
'update_item' => esc_html__( 'Update Venues', 'text-domain' ),
'search_items' => esc_html__( 'Search Venues', 'text-domain' ),
'not_found' => esc_html__( 'Not Found', 'text-domain' ),
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'text-domain' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => esc_html__( 'venues', 'text-domain' ),
'description' => esc_html__( 'Venues news and reviews', 'text-domain' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'main_product_category' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'venues', $args );
希望这会有所帮助。