BuddyDev

Search

[Resolved] How to add a page right under the member page.

  • Participant
    Level: Initiated
    Posts: 17
    maimaimemain on #20740

    Hi there,

    I want to make an original page right under the member page.

    That is, slug look like this↓
    http://example.com/members/smith/original/

    In the following code it will be 404, but what is wrong with this?

    ▼wordpress\wp-content\plugins\bp-custom.php

    /* add page original */
    add_action('bp_setup_nav', 'original_view_tab', 100 );  
    function original_view_tab() {  
    	global $bp;  
    	$user_data = get_user_by( 'id', bp_loggedin_user_id() )->data;
    	bp_core_new_subnav_item(
    		array(  
    		'name' => 'original',
    		'slug' => 'original',  
    		'parent_url' => trailingslashit( bp_loggedin_user_domain() ),
    		'parent_slug' => $user_data->user_nicename, 
    		'show_for_displayed_user' => false, // this page his only
    		'screen_function' => 'original_action',  
    		'position' => 80  
    		)  
    	);  
    }  
    function original_action () {  
    	add_action( 'bp_template_title', 'original_action_title' );  
    	add_action( 'bp_template_content', 'original_action_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }  
    function original_action_title() {  
    	echo 'original';  
    }  
    function original_action_content() {  
    	include_once "buddypress/custom_user/original_content.php"; 
    }

    Thank you for your cooperation in advance.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #20774

    Hi,
    I am sorry for the delayed reply.

    You want something like this?
    https://i.imgur.com/205C8YI.png

    This is called a Component in BuddyPress. I have plans to write some tutorial about it in future.

    For now, You can use ‘bp_core_new_nav_item’ instead of the subnav.

    Also, I suggest either not using

    
    $user_data = get_user_by( 'id', bp_loggedin_user_id() )->data;
    

    or at least putting a check for logged in user. Another change is you don’t need to pass parent_slug for top level nav items.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 17
    maimaimemain on #20777

    Hi, Brajesh

    Oh, please don’t worry!

    Also, thank you for giving me good feedback.

    I changed the following ➀ and ➁.

    if( is_user_logged_in() ){
    $user_data = get_user_by( 'id', bp_loggedin_user_id() )->data;
    }

    bp_core_new_nav_item(
    	array(  
    	'name' => 'original',
    	'slug' => 'original',  
    	//'parent_url' => trailingslashit( bp_loggedin_user_domain() ),
    	//'parent_slug' => $user_data->user_nicename, 
    	'show_for_displayed_user' => false, // this page his only
    	'screen_function' => 'original_action',  
    	'position' => 80  
    	)  
    );

    I’m looking forward to your tutorial.

    Thank you as always.

    Regards
    maimaimemain

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #20781

    Hi maimaimemain,
    Thank you.
    Glad it worked.

    Best regards
    Brajesh

The topic ‘ [Resolved] How to add a page right under the member page.’ is closed to new replies.

This topic is: resolved