Skip to:
Content
Pages
Categories
Search
Top
Bottom

Added a new tab but link doesn't work


  • eflouret
    Participant

    @eflouret

    Hi, this has been asked a lot but in the 90% of the cases the requests are left unsolved (not only here but on other forums too).

    I created a new tab in the members template and it shows as desired. But when I click on the link it loads a page similar to the members root but without a header. Anyway, it doesn’t matter what it shows. The problem is that it doesn’t show what I expected.

    A few considerations:

    1) I copied all the member directory to a buddypress directory in my wordpress theme, so it is like this: /wp-content/themes/mytheme/buddypress/members

    2) I pasted my code in the functions.php file

    3) I’m using BuddyPress 1.8.x

    4) I want the content to load inside the members tempalate. Just like a plugin. Sorry, but I can’t provide a link to my site (is a password protected work in progress).

    here’s the code:

    	function my_bp_nav_adder()
    	{
    		bp_core_new_nav_item(
    			array(
    				'name' => 'My Trips',
    				'slug' => 'mytrips',
    				'position' => 75,
    				'show_for_displayed_user' => true,
    				'screen_function' => 'my_trips_link',
    			));
    	}
    	function my_trips_link () {
    		add_action( 'bp_template_content', 'show_content' );
    		bp_core_load_template( apply_filters('bp_core_template_plugin',  'members/single/plugins' ));
    	}
    	
    	
    	function show_content() {
    	echo 'This is a test';
    	
    	}
    	add_action( 'bp_setup_nav', 'my_bp_nav_adder' );
    

    Thanks!

    Enrique

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp

    1. Not necessary

    4. Try:

    	global $bp;
    	bp_core_new_nav_item( array(
    		'name' => 'My Trips',
    		'slug' => 'mytrips',
    		'position' => 75,
    		'show_for_displayed_user' => true,
    		'screen_function' => 'my_trips_link',
    		'parent_url'      => $bp->loggedin_user->domain . '/',
    		'parent_slug'     => $bp->profile->slug,
    		'default_subnav_slug' => 'mytrips'
    		) );

    eflouret
    Participant

    @eflouret

    Thanks! It worked! I can´t believe that I spent almost four hours trying to figure this out and all I needed was to set the parent slug and url.

    I moved the Buddypress member templates to my theme, inside a directory named Buddypress just because I needed to do some heavy tweaking. This way the templates stay with the main theme and since I uploaded BuddyPress from WordPress control panel, I don´t have permissions to make changes to the templates. I can use the internal wordpress plugin editor, but that would drive me crazy.

    Do you think that moving the templates to the main theme is wrong? Is there a better way to make changes to the templates code? Buddypress template system is like ancient chinese to me.

    Thanks again!

    Enrique


    shanebp
    Moderator

    @shanebp

    @eflouret
    >Do you think that moving the templates to the main theme is wrong?

    No, it’s what you should do when you want to customize templates.
    I thought you did it solely as part of your attempt to get the new nav item working.

    If you want, you can add new templates to that dir.
    And call a template from your show_content function:

    function show_content() { 
    	locate_template( array( 'buddypress/members/single/my-trips.php' ), true );
    }

    eflouret
    Participant

    @eflouret

    Awesome, thanks! I will certainly try that.

    Enrique

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Added a new tab but link doesn't work’ is closed to new replies.
Skip to toolbar