如果你是说像这样
下面是一个方便的类,可以快速完成:
/**
* add_num_to_admin_menu
* @author Ohad Raz <[email protected]>
*/
class add_num_to_admin_menu
{
public $menus = array();
/**
* Class constructor
* @author Ohad Raz <[email protected]>
*
* @param array $args menu => number format
*/
function __construct($args = array()){
if (!is_admin())return;
$this->menus = $args;
add_filter( \'add_menu_classes\', array($this,\'_Add_num\'));
}
/**
* the actual function that adds the number to the menu
*
* @author Ohad Raz <[email protected]>
* @param array $menu admin menu
* @return array
*/
function _Add_num($menu){
//var_dump($menu);
foreach ((array)$this->menus as $name => $number) {
// loop through $menu items, find match, add indicator
foreach( $menu as $menu_key => $menu_data ) {
if( $name != $menu_data[2] )
continue;
$menu[$menu_key][0] .= " <span class=\'update-plugins count-$number\'><span class=\'plugin-count\'>" . number_format_i18n($number) . \'</span></span>\';
}
}
return $menu;
}
/**
* Add a number to a menu
*
* @author Ohad Raz <[email protected]>
* @param string $menu menu to add the number to
* @param int $number number to add
*/
function addMenuNum($menu,$number){
$this->menus[$menu] = $number;
}
}
Usage:
//create an instance of the class
$obj = new add_num_to_admin_menu();
//add a number to a menu node
$obj->addMenuNum(\'edit.php\',7);
//repeat as many times as needed
$obj->addMenuNum(\'upload.php\',20);
$obj->addMenuNum(\'link-manager.php\',15);
$obj->addMenuNum(\'users.php\',10);