自定义帖子类型-在侧边栏中更改名称

时间:2014-09-01 作者:Francesca

我已经创建了一个自定义的帖子类型,因为我正在创建一个以工作列表为特色的网站。

我希望仪表板中的侧栏显示“Jobs”作为名称。

这是我在函数中的代码。php

// Register Custom Post Type
        function custom_post_type() {

            $labels = array(
                \'name\'                => _x( \'Jobs\', \'Post Type General Name\', \'text_domain\' ),
                \'singular_name\'       => _x( \'job\', \'Post Type Singular Name\', \'text_domain\' ),
                \'menu_name\'           => __( \'Post Type\', \'text_domain\' ),
                \'parent_item_colon\'   => __( \'Parent Item:\', \'text_domain\' ),
                \'all_items\'           => __( \'All Jobs\', \'text_domain\' ),
                \'view_item\'           => __( \'View Job\', \'text_domain\' ),
                \'add_new_item\'        => __( \'Add New Job\', \'text_domain\' ),
                \'add_new\'             => __( \'Add New Job\', \'text_domain\' ),
                \'edit_item\'           => __( \'Edit Job\', \'text_domain\' ),
                \'update_item\'         => __( \'Update Job\', \'text_domain\' ),
                \'search_items\'        => __( \'Search Jobs\', \'text_domain\' ),
                \'not_found\'           => __( \'Not found\', \'text_domain\' ),
                \'not_found_in_trash\'  => __( \'Not found in Trash\', \'text_domain\' ),
            );
            $args = array(
                \'label\'               => __( \'custom_job\', \'text_domain\' ),
                \'description\'         => __( \'Jobs Listing\', \'text_domain\' ),
                \'labels\'              => $labels,
                \'supports\'            => array( ),
                \'hierarchical\'        => false,
                \'public\'              => true,
                \'show_ui\'             => true,
                \'show_in_menu\'        => true,
                \'show_in_nav_menus\'   => true,
                \'show_in_admin_bar\'   => true,
                \'menu_position\'       => 5,
                \'can_export\'          => true,
                \'has_archive\'         => true,
                \'exclude_from_search\' => false,
                \'publicly_queryable\'  => true,
                \'capability_type\'     => \'page\',
            );
            register_post_type( \'custom_job\', $args );

        }

        // Hook into the \'init\' action
        add_action( \'init\', \'custom_post_type\', 0 );
然而,出于某种原因,这在WP中显示为侧栏中的“Post Type”。但我看不到它来自哪里。。。我以为name 标签是侧栏中显示的名称吗?

我哪里出错了?

enter image description here

1 个回复
最合适的回答,由SO网友:Robert hue 整理而成

使用这个。请注意“menu\\u name”字段显示的是Jobs now。

// Register Custom Post Type
function custom_post_type() {

  $labels = array(
    \'name\'                => _x( \'Jobs\', \'Post Type General Name\', \'text_domain\' ),
    \'singular_name\'       => _x( \'job\', \'Post Type Singular Name\', \'text_domain\' ),
    \'menu_name\'           => __( \'Jobs\', \'text_domain\' ),
    \'parent_item_colon\'   => __( \'Parent Item:\', \'text_domain\' ),
    \'all_items\'           => __( \'All Jobs\', \'text_domain\' ),
    \'view_item\'           => __( \'View Job\', \'text_domain\' ),
    \'add_new_item\'        => __( \'Add New Job\', \'text_domain\' ),
    \'add_new\'             => __( \'Add New Job\', \'text_domain\' ),
    \'edit_item\'           => __( \'Edit Job\', \'text_domain\' ),
    \'update_item\'         => __( \'Update Job\', \'text_domain\' ),
    \'search_items\'        => __( \'Search Jobs\', \'text_domain\' ),
    \'not_found\'           => __( \'Not found\', \'text_domain\' ),
    \'not_found_in_trash\'  => __( \'Not found in Trash\', \'text_domain\' ),
  );

  $args = array(
    \'label\'               => __( \'custom_job\', \'text_domain\' ),
    \'description\'         => __( \'Jobs Listing\', \'text_domain\' ),
    \'labels\'              => $labels,
    \'supports\'            => array( ),
    \'hierarchical\'        => false,
    \'public\'              => true,
    \'show_ui\'             => true,
    \'show_in_menu\'        => true,
    \'show_in_nav_menus\'   => true,
    \'show_in_admin_bar\'   => true,
    \'menu_position\'       => 5,
    \'can_export\'          => true,
    \'has_archive\'         => true,
    \'exclude_from_search\' => false,
    \'publicly_queryable\'  => true,
    \'capability_type\'     => \'page\',
  );

  register_post_type( \'custom_job\', $args );

}

// Hook into the \'init\' action
add_action( \'init\', \'custom_post_type\', 0 );

结束

相关推荐