Skip to:
Content
Pages
Categories
Search
Top
Bottom

New nav item

  • @muskokee

    Participant

    Hi everyone,

    I know this topic has been asked a million times (searched the forum) but I am having trouble with my particular implementation.

    So, I want to add a new nav item to my main nav list. I am using the code pasted here http://pastebin.com/JuTEZ8GB but have modified the template to load the profile.php page
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/profile' )

    I have made no other modifications to the pastebin code.

    I am using the code in my functions.php file.

    I have added another switch case to the profile.php page

    case 'test'   :
    		bp_get_template_part( 'members/single/profile/test' );
    		break;

    I have a test.php located in the directory.

    When I test my new “test” link which looks like: localhost/site/members/admin/test, the members page loads, i.e. localhost/site/members/

    If I change the “test” link to localhost/site/members/admin/profile/test, I get a 404 error.

    Is there something I have missed??

    Thanks very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • @muskokee

    Participant

    After finding this code

    if ( '' != locate_template( array( 'groups/single/home.php' ), false ) ) {
                        bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
                    } else {
                        add_action( 'bp_template_content_header', create_function( '', 'echo "<ul class="content-header-nav">"; bp_group_admin_tabs(); echo "</ul>";' ) );
                        add_action( 'bp_template_content', array( &$this, 'edit_screen' ) );
                        bp_core_load_template( apply_filters( 'bp_core_template_plugin', '/groups/single/plugins' ) );
                    }

    I am assuming I need to simply load the profile page using the appropriate filter. Now, to find the filter!

    @muskokee

    Participant

    I am abandoning trying to use the profile.php file by adding a case and just going with a new file in members/single/filename using this similar code (which works as intended):

    function custom_bp_nav() {
      global $bp;
      bp_core_new_nav_item(
          array(
              'name'                => __( 'Site Settings', 'buddypress' ),
              'slug'                => 'site-settings',
              'position'            => 80,
              'screen_function'     => 'site_settings_screen',
              'default_subnav_slug' => 'site-settings',
              'parent_url'          => $bp->loggedin_user->domain . $bp->slug . '/',
              'parent_slug'         => $bp->slug
          ) );
    }
    function site_settings_screen() {
      //add title and content here - last is to call the members plugin.php template
      add_action( 'bp_template_title', 'site_settings_screen_title' );
      add_action( 'bp_template_content', 'site_settings_screen_content' );
      bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/test' ) );
    }
    function site_settings_screen_title() {
      echo 'Site Settings';
    }
    function site_settings_screen_content() {
      echo 'Content here';
    }
    add_action( 'bp_setup_nav', 'custom_bp_nav', 50 );

    @danbp

    Participant

    Hi @muskokee,

    Will be faster for me to give you a tutorial.

    – Create a template file, call it testing.php and add it at the root of your child-theme.
    This file should contain a template name in header comment and some minimal html and condition to get a sidebar and a footer. The example comes also with a BP action hook.

    – The template file

    <?php
    /*
    Template Name: Testing
    */
    get_header(); ?>
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    <?php if( is_user_logged_in() ) {
    	
        echo'<h3>My test content title</h3>';
    	do_action( my_testing);
    			
    }?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar( 'front' ); ?>
    <?php get_footer(); ?>

    – Go to page dashboard, and create a new page. Call it Testing and asign in page attributes Testing as template. Save.

    – Open bp-custom.php and copy/paste these functions.

    First we setup the nav on profile with a sub-nav going to our test page.

    function bpfr_post_profile_setup_nav() {
    	global $bp;
    
    	$parent_slug = 'testing';
    	$child_slug = 'testing_sub';	
    	
    	bp_core_new_nav_item( array(
    	'name' => __( 'Testing' ),
    	'slug' => $parent_slug,
    	'screen_function' => 'bpfr_profile_post_screen',
    	'position' => 40,
    	'default_subnav_slug' => $child_slug 
    	) );
    	
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name' => __( 'My Testing' ), 
    	'slug' => $child_slug, 
    	
    	// this slug goes to profile/name/
    	//'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/',
    
    	// this slug goes directly to a page
    	'parent_url' => $bp->root_domain .'/'. $parent_slug .'/',
    	'parent_slug' => $parent_slug, 
    	'screen_function' => 'bpfr_profile_post_screen'
    	) );
    }
    
    function bpfr_profile_post_screen() {	
    	add_action( 'bp_template_content', 'bpfr_profile_post_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    // we took the opportunity to add an action hook. Can be usefull...
    function bpfr_profile_post_screen_content() {
    	do_action( my_testing);
    }
    
    add_action( 'bp_setup_nav', 'bpfr_post_profile_setup_nav' );

    – And because you’re testing, we’ll do a little test by inserting a text directly into the template.

    function action_x() {
    	echo 'Test lorem ipsum, i can read this !';
    }
    add_action( 'my_testing', 'action_x' );

    Now you can read the snippet, add you’re own html, loops and hooks to the template file, or simply publish something on the page… Hope you’ll understand how this is working. Happy testing !

    @muskokee

    Participant

    Thank you so much @danbp! Again that is 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘New nav item’ is closed to new replies.
Skip to toolbar