Menu Buddypress新建配置文件选项卡和子选项卡:如何正确设置url slug?

Menu Buddypress新建配置文件选项卡和子选项卡:如何正确设置url slug?,menu,tabs,profile,buddypress,Menu,Tabs,Profile,Buddypress,首先,我见过很多人尝试做类似的任务,即创建一个新选项卡,在用户配置文件菜单中包含子选项卡。我已经设法做到了这一点,但我似乎无法让url slug正常工作。当我单击第一个子选项卡时,它只会将我带回用户配置文件的主页面,当我单击任何其他子选项卡时,我会收到404个错误。我有一种感觉,我错过了一些非常简单的东西,在过去的几周里,我一直在努力学习如何在没有任何运气的情况下让这项工作成功。如果有人能帮助指导我如何让这个工作正常,我将非常感激,我想很多其他人会发现这个职位在未来有用 对于记录,主配置文件选项

首先,我见过很多人尝试做类似的任务,即创建一个新选项卡,在用户配置文件菜单中包含子选项卡。我已经设法做到了这一点,但我似乎无法让url slug正常工作。当我单击第一个子选项卡时,它只会将我带回用户配置文件的主页面,当我单击任何其他子选项卡时,我会收到404个错误。我有一种感觉,我错过了一些非常简单的东西,在过去的几周里,我一直在努力学习如何在没有任何运气的情况下让这项工作成功。如果有人能帮助指导我如何让这个工作正常,我将非常感激,我想很多其他人会发现这个职位在未来有用

对于记录,主配置文件选项卡可以正常工作,但子选项卡不能正常工作

下面是我当前在bp-custom.php文件中的代码

// My Membership Profile Tab
function profile_new_nav_item() {

global $bp;

bp_core_new_nav_item(
array(
    'name'                => 'My Membership',
    'slug'                => 'my-membership',
    'default_subnav_slug' => 'extra_sub_tab', // We add this submenu item below
    'screen_function'     => 'view_manage_tab_main'
)
);
}


add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );

function view_manage_tab_main() {
add_action( 'bp_template_content', 'bp_template_content_main_function' );
bp_core_load_template( 'template_content' );
}

function bp_template_content_main_function() {
if ( ! is_user_logged_in() ) {
    wp_login_form( array( 'echo' => true ) );
}
}

function profile_new_subnav_item() {
global $bp;

bp_core_new_subnav_item( array(
    'name'            => 'Membership Level',
    'slug'            => 'extra_sub_tab',
    'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[      'extra_tab' ][ 'slug' ] . '/',
    'parent_slug'     => $bp->bp_nav[ 'my-membership' ][ 'slug' ],
    'position'        => 10,
    'screen_function' => 'view_manage_sub_tab_main'
) );
}

add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );

function view_manage_sub_tab_main() {
add_action( 'bp_template_content', 'bp_template_content_sub_function' );
bp_core_load_template( 'template_content' );
}

function bp_template_content_sub_function() {
if ( is_user_logged_in() ) {
    //Add shortcode to display content in sub tab
    echo do_shortcode( '[membership]' );
} else {
    wp_login_form( array( 'echo' => true ) );
}
}

// My Billing Profile Tab

function profile_new_subnav_item_billing() {
global $bp;

bp_core_new_subnav_item( array(
    'name'            => 'Billing',
    'slug'            => 'extra_sub_tab_billing',
    'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[    'extra_tab' ][ 'slug' ] . '/',
    'parent_slug'     => $bp->bp_nav[ 'my-membership' ][ 'slug' ],
    'position'        => 20,
    'screen_function' => 'view_manage_sub_tab_billing'
) );
}

add_action( 'bp_setup_nav', 'profile_new_subnav_item_billing', 20 );

function view_manage_sub_tab_billing() {
add_action( 'bp_template_content',     'bp_template_content_sub_function_billing' );
bp_core_load_template( 'template_content' );
}

function bp_template_content_sub_function_billing() {
if ( is_user_logged_in() ) {
    //Add shortcode to display content in sub tab
    echo do_shortcode( '[billing]' );
} else {
    wp_login_form( array( 'echo' => true ) );
}
}
你可以使用这个:

 // define your parent slug
 $parent_slug = 'activity';
  bp_core_new_subnav_item( array( .........   
    'parent_url'      => $bp->loggedin_user->domain . $parent_slug.'/',
    'parent_slug'     => $parent_slug,
它对我有用