2017-03-26 1 views
0

私はWordpressでカスタムポストタイプを作っています。 投稿タイプ名の記事にラベルを表示します。翻訳カスタムポストタイプ

私はこれを行う:

<?php echo get_post_type(); ?> 

それは英語名を出力します。

私はPoeditと翻訳したいと思いますが、これはうまくいきません。 マイカスタムポストタイプは次のようになります。

<?php 


function register_cpt_news() { 

    $singular = 'News'; 
    $plural = 'News'; 


    $labels = array(
     'name'    => _x($plural, 'ndi'), 
     'singular_name'  => _x($singular, 'ndi'), 
     'menu_name'   => _x('News', 'ndi'), 
     'name_admin_bar'  => _x($singular, 'ndi'), 
     'add_new'   => __('Add New'), 
     'add_new_item'  => __('Add New '.$singular), 
     'new_item'   => __('New '.$singular), 
     'edit_item'   => __('Edit '.$singular), 
     'view_item'   => __('View '.$singular), 
     'all_items'   => __('All '.$plural), 
     'search_items'  => __('Search '.$plural), 
     'parent_item_colon' => __('Parent '.$plural.':'), 
     'not_found'   => __('No '.$plural.' found.'), 
     'not_found_in_trash' => __('No '.$plural.' found in Trash.'), 
    ); 

    $args = array(
     'label'    => __($plural, 'ndi'), 
     'labels'    => $labels, 
     'supports'   => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions',), 
     'hierarchical'  => false, 
     'public'    => true, 
     'show_ui'    => true, 
     'show_in_menu'  => true, 
     'show_in_nav_menus' => true, 
     'show_in_admin_bar' => true, 
     'menu_position'  => 4, 
     'can_export'   => true, 
     'has_archive'   => true , 
     'exclude_from_search' => false, 
     'publicly_queryable' => true, 
     'capability_type'  => 'page', 
     'menu_icon'   => 'dashicons-format-aside', 
    ); 

    register_post_type('news', $args); 

} 


add_action('init', 'register_cpt_news'); 

?> 

ワット私が間違っているの?あなたは英語でそれを作った英語使用のラベル名

$title_lan = $obj->labels->name ; 
echo $title_lan ; 

でカスタムポスト名をエコーし​​たいときに、カスタムポストを登録するとき

答えて

0

あなたは、このメソッド

$obj = get_post_type_object('postName') ; 

を使用することができます

他の言語でカスタム投稿名をエコーする場合

$title_lan = $obj->labels->menu_name ; 

echo $title_lan ; 

あなたがカスタム投稿を登録したときに他の言語で作成したもの