WordPress函数文档add_group()
向工具栏加入一组自定义链接 描述 This function adds a new group to the …
向工具栏加入一组自定义链接
描述
This function adds a new group to the Toolbar. Groups allow you to group Toolbar items together into distinct sections of a toolbar menu.
The Toolbar replaces the Admin Bar since WordPress Version 3.3.
Toolbar items are also called “nodes”. Nodes can be parents for other nodes, which creates dropdown menus. When adding a group you’re actually adding a group node. Group nodes are not visible in the Toolbar, but nodes added to it are.
note: This function is a method of the WP_Admin_Bar class and $wp_admin_bar global object, which may not exist except during the ‘admin_bar_menu’ or ‘wp_before_admin_bar_render’ hooks.
用法
<?php $wp_admin_bar->add_group( $args ); ?>
参数
$args
(array) (必填) An array of arguments.
默认值: None
Arguments
id
(string) (必填) The ID of the group (node).
默认值: false
parent
(string) (可选) The ID of the parent node.
默认值: false
meta
(array) (可选) An array of meta data for the group (node).
默认值: array()
- ‘class’ – The class attribute for the unordered list containing the child nodes.
示例
Adding a group to a parent node
This example adds a parent node, child nodes and a group to the toolbar.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
add_action( ‘admin_bar_menu’, ‘add_nodes_and_groups_to_toolbar’, 999 );
function add_nodes_and_groups_to_toolbar( $wp_admin_bar ) {
// add a parent item
$args = array(
‘id’ => ‘parent_node’,
‘title’ => ‘parent node’
);
$wp_admin_bar->add_node( $args );
// add a child item to our parent item
$args = array(
‘id’ => ‘child_node’,
‘title’ => ‘child node’,
‘parent’ => ‘parent_node’
);
$wp_admin_bar->add_node( $args );
// add a group node with a class “first-toolbar-group”
$args = array(
‘id’ => ‘first_group’,
‘parent’ => ‘parent_node’,
‘meta’ => array( ‘class’ => ‘first-toolbar-group’ )
);
$wp_admin_bar->add_group( $args );
// add an item to our group item
$args = array(
‘id’ => ‘first_grouped_node’,
‘title’ => ‘first group node’,
‘parent’ => ‘first_group’
);
$wp_admin_bar->add_node( $args );
// add another child item to our parent item (not to our first group)
$args = array(
‘id’ => ‘another_child_node’,
‘title’ => ‘another child node’,
‘parent’ => ‘parent_node’
);
$wp_admin_bar->add_node( $args );
}
|
The output from this example in the toolbar will be:
1
2
3
4
5
6
7
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
* parent node
** child node
** another child node
** first group node
|
源文件
add_group() 函数的代码位于 wp-includes/class-wp-admin-bar.php
.
相关
Toolbar API
- Article(文章): The WordPress Toolbar
- Class(类): WP_Admin_Bar
- Function(函数): add_node()
- Function(函数): remove_node()
- Function(函数): add_menu()
- Function(函数): remove_menu()
- Function(函数): add_group()
- Function(函数): get_node()
- Function(函数): get_nodes()
- 原文:http://codex.wordpress.org/Function_Reference/add_group
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!