question: I am trying to create a new sub nav item for the groups on buddy press I am using bp_core_new_subnav_item
to do it and passing the screen_function
, but the tab is not displaying on the group page
Any ideas where I should be looking on this?
Heres our code.
bp_core_new_nav_item( array(
'name' => 'Document List',
'slug' => 'group-document-list',
'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/',
'parent_slug' => $bp->groups->slug,
'screen_function' => 'group_document_list_function_to_show_screen',
'position' => 55 ) );
function group_document_list_function_to_show_screen() {
//add title and content here - last is to call the members plugin.php template
add_action( 'bp_template_title', 'group_document_list_function_to_show_screen_title' );
add_action( 'bp_template_content', 'group_document_list_function_to_show_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function group_document_list_function_to_show_screen_title() {
echo 'Documents for this group';
}
function group_document_list_function_to_show_screen_content() {
display_group_document_list();
}
Make sure that you only attempt to set up the items after BP has set up its core navigation. You can ensure this by hooking to
bp_setup_nav
with a priority higher than10
.Thus:
Keep in mind that, as written, this code is intended to add a subnav tab to the
Groups
subnav of a user profile. If you want to attach it to a single group instead, you need to relativize it to groups, using a differentparent_slug
andparent_url
:To be honest, though, if you want to be adding subnav items to BP Groups, your best bet is to use the BP Group Extension API http://codex.buddypress.org/developer-docs/group-extension-api/. You just fill in a few methods, and all the BP-specific navigation logic is done for you. If there are methods (like
create_screen()
you’re not going to use, just leave them blank.