1

When adding a custom tab to the BuddyPress menu i cant load the right template. I think somethings is wrong with the path since I end on the member page who lists all members.

I get this url in my browser: mydomain.com/members/johndoe/myads but it just list all members and not the content from myads.php

I have added myads.php in: wp-content/plugins/buddypress/bp-themes/bp-default/members/single/myads.php and wp-content/themes/my-theme/myads.php

// Set up Cutsom BP navigation
function my_setup_nav() {
  global $bp;

  bp_core_new_nav_item( array( 
        'name' => __( 'My ads', 'buddypress' ), 
        'slug' => 'myads', 
        'position' => 30,
        'screen_function' => 'my_item_one_template', 
  ) );

  // Change the order of menu items
  $bp->bp_nav['messages']['position'] = 100;
}

add_action( 'bp_setup_nav', 'my_setup_nav' );

// Load a page template for your custom item. You'll need to have an myads.php in your theme root.

function my_item_one_template() {
  bp_core_load_template( 'myads');
}

closed as off-topic by Pieter Goosen, Mark Kaplun, birgire, cybmeta, Bainternet Dec 12 '14 at 10:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

Try this:

function my_setup_nav() {
  global $bp;

  bp_core_new_nav_item( array( 
      'name' => __( 'My ads', 'buddypress' ),
      'parent_slug' => $bp->profile->slug,
      'slug' => 'myads', 
      'position' => 30,
      'screen_function' => 'my_item_one_template',
      'default_subnav_slug' => 'myads' 
  ) );

}

add_action( 'bp_setup_nav', 'my_setup_nav' );

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

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

Put myads.php in your theme or child theme in this folder structure: [theme]/buddypress/members/single/myads.php

If it still doesn't find the template, you have to register the template so the BP can find it in the template stack. That can be rather complex. An easier method is to put the code directly in the function:

function my_item_create_screen() { 
?>
   <h2>MY ADS</h2>  
<?php 
}
  • Hi @shanebp I tried to use both your solutions but both takes me to the list all members page? Any ideas? – user3906056 Dec 7 '14 at 1:15
  • Sorry, forgot the 'default_subnav_slug' field in bp_core_new_nav_item. See edit above. – shanebp Dec 7 '14 at 13:13
  • thx, now the first solution works! :) – user3906056 Dec 8 '14 at 14:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.