Skip to:
Content
Pages
Categories
Search
Top
Bottom

how display content in submenu?


  • luisa227
    Participant

    @luisa227

    Hello, sorry for my bad english but I’m Italian. I want to create a sub-menu under the menu Activity (and this is ok) and view a template’s page when I click on the sub-menu. I can not do this last step: associate the template. If I make an item (not sub) it’s work but if I make the sub-item don’t work.
    I think that the error is on this line:
    bp_core_load_template( apply_filters( 'bp_core_template_plugin','members/single/swap' ) );
    And where do I put the file swap.php? in which folder? Thank you
    This is my code:

    
    function bpfr_custom_profile_sub_nav() {
    	global $bp;
    	$parent_slug = 'activity';
    		
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name'            => __( 'Swap' ), 
    	'slug'            => 'swap', 
    	
    	'parent_url'      => $bp->displayed_user->domain . $parent_slug.'/', 
    
    	
    	'parent_slug'     => $parent_slug, 
    	//'parent_slug'         => $bp->slug
    	'screen_function' => 'swapluisa',
    	'position'        => 1,
    	
    	) );
    }
    add_action( 'bp_setup_nav', 'bpfr_custom_profile_sub_nav' );
    	
    
    function swapluisa() {
    	//add title and content here - last is to call the members plugin.php template
    	add_action( 'bp_template_title', 'my_groups_page_function_to_show_screen_title' );
    	add_action( 'bp_template_content', 'my_groups_page_function_to_show_screen_content' );
    	 bp_core_load_template( apply_filters( 'bp_core_template_plugin','members/single/swap' ) );
    	
    }
    
    add_action( 'bp_setup_nav', 'my_bp_nav_adder', 50 );
    function my_groups_page_function_to_show_screen_title() {
    	echo 'My new Page Title';
    }
    
    function my_groups_page_function_to_show_screen_content() {
    	echo 'My Tab content here';
    
    }
Viewing 15 replies - 1 through 15 (of 15 total)

  • shanebp
    Moderator

    @shanebp

    Delete your call to
    bp_core_load_template( apply_filters( 'bp_core_template_plugin','members/single/swap' ) );

    Use this call

    function my_groups_page_function_to_show_screen_content() {
    	bp_get_template_part('members/single/swap');
    }

    Add these functions:

    function luisa_register_template_location() {
        return 'path to your templates' . '/templates/';
    }
    
    function luisa_template_start() {
    
        if( function_exists( 'bp_register_template_stack' ) )
            bp_register_template_stack( 'luisa_register_template_location' );
    
    }
    add_action( 'bp_init', 'luisa_template_start' );

    luisa227
    Participant

    @luisa227

    thanks but it don’t work, or better… I don’t know where is my template folder… I’m confused on the right folder… I inserted the code in my file bp-custom.php on the theme’s plugin folder.

    Where I have to create my own template? in my child theme? or under the buddypress ‘s plugin folder?? Or where?

    can you do me a practical example of how to enter the correct URL?
    You can also explain the function of the code you quoted?
    thank you


    danbp
    Moderator

    @danbp

    Hi @luisa227,

    considering your questions, i would suggest you read attentively both WP and BP codex.

    child theme
    bp-custom

    bp-custom.php goes to wp-content/plugins/ directory, not into the (child)theme folder.

    such path members/single/swap is related to BP legacy by default.

    But as swap is a custom folder, that custom path means in fact wp-content/themes/child-theme/buddypress/members/single/swap.php, where /child-theme/buddypress/contains copies of all your customized legacy files and your own additionnal files you want to use.

    Hopefully reading the codex will help you to understand a little better how all this works together.


    luisa227
    Participant

    @luisa227

    sorry 🙁 i don’t know!!!
    I seem to do correctly, but does not work.
    I also for testing entered my files everywhere, but does not find it anywhere !!!

    In my web-site the URL is http://mysite.it/membri/testmember1/activity/swap/ but it says “We are sorry, but the page you are looking for does not exist.”

    I have my swap.php (into there’s only a echo command)’s file in wp-content/themes/child-theme/buddypress/members/single/
    and in bp-custom.php (that is in my plugin folder) I write

    
    
    function my_groups_page_function_to_show_screen_content() {
    	bp_get_template_part('members/single/swap');
    }
    function luisa_register_template_location() {
       return 'wp-content/themes/betheme-child/buddypress/members/single';
    }

    I try also to put the swap.php file into wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single but nothing is happen.

    where am I wrong? thanks


    danbp
    Moderator

    @danbp

    Read here:

    Template Overload from a Plugin

    Here a working example you can study to understand (and use to see how it works)

    function bpfr_post_profile_setup_nav() {
    global $bp;
    
    	$parent_slug = 'audio';
    	$child_slug = 'posts_sub';	
    	$post_count = count_user_posts(  bp_displayed_user_id(), array('post', 'post' ) );
    
    		//Add nav item with posts count
    		bp_core_new_nav_item( array(
    			'name' => __( 'Audios' ) .'<span>'.$post_count.'</span>',
    			'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 latest audios' ),
    			'slug' => $child_slug, 
    			'parent_url' => $bp->loggedin_user->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' ) );
    	}
    
    	function bpfr_profile_post_screen_content() {
    		do_action( 'my_profile_post' );
    	}
    
    add_action( 'bp_setup_nav', 'bpfr_post_profile_setup_nav' );

    And here a content test:

    function luisa_conteni() {
       echo 'Forza BuddyPress';
    }
    add_action( 'my_profile_post', 'luisa_conteni' );

    Add all snippets to bp-custom.php.

    The example use the default plugin template (/members/single/plugin.php) as generally there is no need to create a new template while on a profile (except if you need something very specific like a table or a an iframe).


    luisa227
    Participant

    @luisa227

    I do not want to regurgitate, but really, for me not knowing English well is very difficult to understand and the last posted code returns as explained to me at the beginning and that is that if I enter the submenu item not like the whole thing works but if I want to insert the voice within an existing tab I change something and I can not understand what. I don’t undersatand.

    I beg you, please, if you can give me extra help, this time.
    They are days that are on this issue and I can not go on, I am also physically ill and I can not concentrate on the solution, please … a little help more!


    danbp
    Moderator

    @danbp

    Now, it’s me who doesn’t understand ! What do you want to do finally ? What is not working for you ?

    Or try to get some help on the italian WP forum.

    Support Forums


    or get in touch with one of BP’s italian translator for help or at least some explanation
    Italian BP translators list


    luisa227
    Participant

    @luisa227

    Simple. I want to make functional code

    My actual code is:

    function bpfr_custom_profile_sub_nav() {
    	global $bp;
    	$parent_slug = 'activity';
    		
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name'            => __( 'Swap' ), 
    	'slug'            => 'swap', 
    	
    	'parent_url'      => $bp->displayed_user->domain . $parent_slug.'/', 
    
    	
    	'parent_slug'     => $parent_slug, 
    	
    	'screen_function' => 'swapluisa',
    	'position'        => 1,
    	
    	) );
    }
    add_action( 'bp_setup_nav', 'bpfr_custom_profile_sub_nav' );
    
    					
    	
    		
    
    function swapluisa() {
    	
    	add_action( 'bp_template_title', 'my_groups_page_function_to_show_screen_title' );
    	add_action( 'bp_template_content', 'my_groups_page_function_to_show_screen_content' );
    }
    
    add_action( 'bp_setup_nav', 'my_bp_nav_adder', 50 );
    function my_groups_page_function_to_show_screen_content() {
    	
    	return bp_get_template_part('members/single/swap');
    // (OR THIS???) return bp_get_template_part('wp-content/themes/betheme-child/buddypress/members/single');
    }
    
    function my_groups_page_function_to_show_screen_title() {
    	echo 'My new Page Title';
    }
    
    function luisa_register_template_location() {
       return 'members/single/';
    // (OR THIS????) return 'members/single/';wp-content/themes/betheme-child/buddypress/members/single'
    }
    
    function luisa_template_start() {
    
        if( function_exists( 'bp_register_template_stack' ) )
           bp_register_template_stack( 'luisa_register_template_location' );
    
    }
    add_action( 'bp_init', 'luisa_template_start' );
    

    but dont’work!

    I repeat, surely accidentally pointing to the folder, I can not figure out the exact solution. when i write “OR THIS??” i try but don’t work.

    where am I wrong? thanks


    luisa227
    Participant

    @luisa227

    I have a certain page “Swap” full of functions and associations to other pages formed by a plugin called “swap”. I must associate this page to BuddyPress menu.

    I tried BuddyPress Custom Profile menu’s plugin and made me properly create my swap page, but: 1) remains as the last position, and I would like the first; 2) I will only appear on my profile as I would like for all of the users.
    So not good.

    As an alternative, I tried to create through my code menu item (and I can put it in first position and for all users) with the code inside of swap page, just as there are php functions related to other non correctly display the content. Because my template is in the folder of my theme BuddyPress child, and to make it work well should I leave it in my folder of the swap plugin. (Ie wp-content / plugins / swap / front / views)

    My question is: how do I make the point to all there in that folder? it is feasible? Or is feasible to act on the plugin configuration BuddyPress Custom Profile Menu and resolve the position and visibility for all? thanks


    luisa227
    Participant

    @luisa227

    It’s OK. I resolved It!!! 🙂


    danbp
    Moderator

    @danbp

    Forgot custom profile menu plugin and use custom code, as it is much simplier.

    Here another example, with Swap at the first position on the buddybar on profiles.

    function bpfr_swap_luisa_nav() {
    global $bp;
    
    	$parent_slug = 'swap';
    	$child_slug = 'swap_sub';		
    
    		//Add nav item 
    		bp_core_new_nav_item( array(
    			'name' => __( 'Swap' ),
    			'slug' => $parent_slug,
    			'screen_function' => 'bpfr_profile_swap_screen',
    			'position' => 10, // 10 is the first position on buddybar
    			'default_subnav_slug' => $child_slug 
    		) );
    		
    		//Add subnav item 	 
    		bp_core_new_subnav_item( array( 
    			'name' => __( 'My Swaps' ),
    			'slug' => $child_slug, 
    			'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/', 
    			'parent_slug' => $parent_slug, 
    			'screen_function' => 'bpfr_profile_swap_screen'
    		) );
    
    	}
    
    	function bpfr_profile_swap_screen() {	
    		add_action( 'bp_template_content', 'bpfr_profile_swap_screen_content' );
    		bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    	}
    
    	function bpfr_profile_swap_screen_content() {
    		do_action( 'my_profile_swap' );
    	}
    
    add_action( 'bp_setup_nav', 'bpfr_swap_luisa_nav' );
    

    The following function introduce the content related to Swap. As i ignore how that plugin works, i can’t give you a working example for it. It would be nice to indicate the exact plugin name and upload url. Also is it compatible with BP ?

    function bpex_swap_stuff() {
    ?>
    <h2>Lorem Ipsum for ever !</h2>
    <p>Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet.</p>
    <?php
    }
    add_action( 'my_profile_swap', 'bpex_swap_stuff' );

    danbp
    Moderator

    @danbp

    @luisa227,

    merged your both topics.

    As you asked a lot before finding, it would be great to help others by giving the solution you found to solve your problem.


    luisa227
    Participant

    @luisa227

    I solved it by acting directly on the plug-in code BuddyPress Custom Profile Menu and changing the position of the slug and the display for all user.

    But soon as I get the chance I’ll try with the custom code without using plugins (many would give more satisfaction!). Thanks!


    danbp
    Moderator

    @danbp

    Thanks for sharing. But take in account that such solution is not recommended as your modification will be overwritten at next plugin update.
    Never, under any circumstances, should you hack core files.

    Don’t forget to save a copy of your modified file in a safe place, so you can remember later what you’ve done, as it seems you forget easily such details 😉


    luisa227
    Participant

    @luisa227

    Thank you!

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
Skip to toolbar