【问题标题】:Add custom tab and page to BuddyPress profile page将自定义选项卡和页面添加到 BuddyPress 个人资料页面
【发布时间】:2015-01-25 23:11:33
【问题描述】:

我正在尝试在 BuddyPress 的“用户配置文件”菜单中创建一个额外的选项卡。 到目前为止,我可以在菜单中看到选项卡,但是当我单击选项卡时,我被引导到另一个页面,在那里我可以看到所有内容的顶部和用户活动列表,而不是看到内容在菜单下(例如当您单击活动、朋友、消息等时) 我希望这是有道理的......这是我的代码:

 function my_setup_nav() {
    global $bp;

    bp_core_new_nav_item( array( 
          'name' => __( 'Tester', 'buddypress' ), 
          'slug' => 'tester', 
          'position' => 30,
          'screen_function' => 'test_template', 
    ) );
  }

  function test_template() {
    add_action( 'bp_template_content', 'test_template_two' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  }

  function test_template_two() { 
    locate_template( array( 'buddypress/members/single/tester.php' ), true );
  }

所以,我可以看到带有“Tester”文本的选项卡,但是当我单击时,我会被定向到另一个页面 (http://localhost/my-site/members/my-user/tester/),其中“tester.php”的内容显示在用户活动上方。

提前谢谢你。

【问题讨论】:

    标签: wordpress buddypress


    【解决方案1】:

    这会有所帮助,

    function profile_new_nav_item() {
    
        global $bp;
    
        bp_core_new_nav_item(
        array(
            'name'                => 'Extra Tab',
            'slug'                => 'extra_tab',
            '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'            => 'Extra Sub Tab',
            'slug'            => 'extra_sub_tab',
            'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[ 'extra_tab' ][ 'slug' ] . '/',
            'parent_slug'     => $bp->bp_nav[ 'extra_tab' ][ '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
        } else {
            wp_login_form( array( 'echo' => true ) );
        }
    }
    

    【讨论】:

    • 谢谢。这很有帮助。
    • bp_nav 已弃用。请改用bp_get_current_group_slug()。例如:'parent_slug' => bp_get_current_group_slug();
    • Extra Sub Tab 只是显示类似内容并且没有自己的 url 吗?有更新吗?
    【解决方案2】:

    查看BuddyPress Custom Profile Menu plugin。它允许您将常规 WordPress 菜单附加到 BuddyPress 用户个人资料页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多