BuddyPress: Adding a new tab in groups

I'm trying to add a new tab to my groups on BuddyPress. All the groups will have different content preferrably from

I'm trying to add a new tab to my groups on BuddyPress. All the groups will have different content preferrably from the database.

How can I accomplish this?

I'm trying to add a new tab to my groups on BuddyPress. All the groups will have different content preferrably from the database.

How can I accomplish this?

Share Improve this question asked Jan 11, 2011 at 13:19 AndersAnders 2094 silver badges11 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 5

There's an example of this on the buddypress forums which is a good place to start looking for answers.

http://buddypress/community/groups/creating-extending/forum/topic/can-someone-explain-how-to-add-tabs-to-the-profile-page/

For the sake of answering here though here goes:

bp_core_new_subnav_item( array(
   'name' => 'My Group Page',
   'slug' => 'my-group-page',
   'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/',
   'parent_slug' => $bp->groups->slug,
   'screen_function' => 'my_groups_page_function_to_show_screen',
   'position' => 40 ) );

And the screen function to render the page:

function my_groups_page_function_to_show_screen() {

    //add title and content here - last is to call the members plugin.php template
    add_action( 'bp_template_title', 'my_groups_page_function_to_show_screen_title' );
    add_action( 'bp_template_content', 'my_groups_page_function_to_show_screen_content' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

    function my_groups_page_function_to_show_screen_title() {
        echo 'My Page Title';
    }
    function my_groups_page_function_to_show_screen_content() { 

        // page content goes here

    }

This worked for me:

function setup_group_nav(){
    global $bp; 
    /* Add some group subnav items */
    $user_access = false;
    $group_link = '';
    if( bp_is_active('groups') && !empty($bp->groups->current_group) ){
        $group_link = $bp->root_domain . '/' . bp_get_groups_root_slug() . '/' . $bp->groups->current_group->slug . '/';
        $user_access = $bp->groups->current_group->user_has_access;
        bp_core_new_subnav_item( array( 
            'name' => __( 'Custom', 'custom'),
            'slug' => 'custom', 
            'parent_url' => $group_link, 
            'parent_slug' => $bp->groups->current_group->slug,
            'screen_function' => 'bp_group_custom', 
            'position' => 50, 
            'user_has_access' => $user_access, 
            'item_css_id' => 'custom' 
        ));
    }
}
add_action( 'bp_init', 'setup_group_nav' );

function bp_group_custom() {
    add_action('bp_template_title', 'my_new_group_show_screen_title');
    add_action('bp_template_content', 'my_new_group_show_screen_content');

    $templates = array('groups/single/plugins.php', 'plugin-template.php');
    if (strstr(locate_template($templates), 'groups/single/plugins.php')) {
        bp_core_load_template(apply_filters('bp_core_template_plugin', 'groups/single/plugins'));
    } else {
        bp_core_load_template(apply_filters('bp_core_template_plugin', 'plugin-template'));
    }

}

function my_new_group_show_screen_title() {
    echo 'New Tab Title';
}

function my_new_group_show_screen_content() {
    echo 'New tab page content';

}

For your example to work, you need to wrap it in a function like this (that you'll place in functions.php) :

function my_setup_nav() {
    global $bp;
    bp_core_new_subnav_item( array(
       'name' => 'My Group Page',
       'slug' => 'my-group-page',
       'parent_url' => $bp->loggedin_user->domain . $bp->groups->slug . '/',
       'parent_slug' => $bp->groups->slug,
       'screen_function' => 'my_groups_page_function_to_show_screen',
       'position' => 40 ) );
}
add_action( 'bp_setup_nav', 'my_setup_nav' );

and place you rendreing function after obviously.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745226606a4617489.html

相关推荐

  • BuddyPress: Adding a new tab in groups

    I'm trying to add a new tab to my groups on BuddyPress. All the groups will have different content preferrably from

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信