首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将CPT“添加新职位”更改为CPT名称

将CPT“添加新职位”更改为CPT名称
EN

Stack Overflow用户
提问于 2018-11-11 18:08:17
回答 2查看 488关注 0票数 0

如何更改“添加新帖子”以反映自定义post类型的名称?我是否在下面的代码中添加了什么。我知道这是可以做到的..。

代码语言:javascript
复制
function create_post_type() {
  register_post_type( 'venues',
    array(
      'labels' => array(
        'name' => __( 'Venues' ),
        'singular_name' => __( 'Venue' )
      ),
  );

屏幕截图

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-11 19:36:32

在标签数组中添加:

代码语言:javascript
复制
'add_new'            => _x( 'Add New', 'venue', 'your-plugin-textdomain' ),
'add_new_item'       => __( 'Add New Venue', 'your-plugin-textdomain' ),

也可以阅读WordPress代码库:类型

票数 1
EN

Stack Overflow用户

发布于 2018-11-12 10:46:41

您可以使用下面的代码来获得预期的结果。

代码语言:javascript
复制
<?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 );

希望这能帮上忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53251680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档