功能register_post_type() 接受参数\'labels\'
. 这是一个数组,其中一个可能的键名为…tada…\'menu_name\'
.
示例代码
register_post_type(
\'academias\'
, array (
\'can_export\' => TRUE
, \'exclude_from_search\' => FALSE
, \'has_archive\' => TRUE
, \'hierarchical\' => TRUE
, \'label\' => \'Academias\'
, \'labels\' => array ( \'menu_name\' => \'See All Academias\' )
, \'menu_position\' => 5
, \'public\' => TRUE
, \'publicly_queryable\' => TRUE
, \'query_var\' => \'academias\'
, \'rewrite\' => array ( \'slug\' => \'academias\' )
, \'show_ui\' => TRUE
, \'show_in_menu\' => TRUE
, \'show_in_nav_menus\' => TRUE
, \'supports\' => array ( \'editor\', \'title\' )
)
);
更新现在,我已经更好地理解了你的问题,似乎只有一种方法可以实现你想要的:加入
attribute_escape
.
测试插件
<?php
/*
Plugin Name: *WPSE13210
*/
! defined( \'ABSPATH\' ) and exit;
add_action( \'init\', \'register_academia\' );
/**
* Registers te post type academias
*
* @return void
*/
function register_academia()
{
register_post_type(
\'academias\'
, array (
\'can_export\' => TRUE
, \'exclude_from_search\' => FALSE
, \'has_archive\' => TRUE
, \'hierarchical\' => TRUE
, \'label\' => \'Academias\'
, \'labels\' => array (
\'menu_name\' => \'See All Academias\'
, \'name\' => \'Academias\'
)
, \'menu_position\' => 5
, \'public\' => TRUE
, \'publicly_queryable\' => TRUE
, \'query_var\' => \'academias\'
, \'rewrite\' => array ( \'slug\' => \'academias\' )
, \'show_ui\' => TRUE
, \'show_in_menu\' => TRUE
, \'show_in_nav_menus\' => TRUE
, \'supports\' => array ( \'editor\', \'title\' )
)
);
}
add_filter( \'attribute_escape\', \'rename_second_menu_name\', 10, 2 );
/**
* Renames the first occurence of \'See All Academias\' to \'Academias\'
* and deactivates itself then.
* @param $safe_text
* @param $text
*/
function rename_second_menu_name( $safe_text, $text )
{
if ( \'See All Academias\' !== $text )
{
return $safe_text;
}
// We are on the main menu item now. The filter is not needed anymore.
remove_filter( \'attribute_escape\', \'rename_second_menu_name\' );
return \'Academias\';
}
不是很优雅,但至少有一个解决方案…
2010年5月12日更新ticket 17378 新参数all_items
已提议。一旦它成为核心的一部分,应该会工作得更好…