BuddyPress:在群组中添加新标签

时间:2011-01-11 作者:Anders

我正试图在BuddyPress上为我的组添加一个新选项卡。所有组都将有不同的内容,最好来自数据库。

我如何才能做到这一点?

3 个回复
最合适的回答,由SO网友:sanchothefat 整理而成

buddypress论坛上有一个这样的例子,这是一个开始寻找答案的好地方。

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

为了回答这个问题,下面是:

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 ) );
以及用于呈现页面的屏幕功能:

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

    }

SO网友:MastaBaba

这对我很有用:

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\';

}

SO网友:user28591

为了使示例正常工作,您需要将其包装到如下函数中(您将把它放在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\' );
并将您的渲染功能放在后面。

结束

相关推荐

我如何才能检测到我的主题中的BuddyPress页面是否处于活动状态?

我试图将子菜单加入到我的主题中,但在导航到BuddyPress页面时遇到了问题(与标准WP页面、帖子等相反)。基本上,我想做的是让页面(在适当的情况下)显示一个子菜单,ala:但当我浏览到BuddyPress控制下的页面时,我会得到以下信息:我使用以下命令生成子菜单:if (is_page()) { global $wp_query; if( empty($wp_query->post->post_parent) ) { $parent = $