Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been trying to add 2 tabs on user profile. “posts”,”gallery”

posts : my posted posts. it will display a custom-post-type “user-post”

gallery : my pictures .. or any thing.. it will display a custom-post-type “user-images”

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

  bp_core_new_nav_item( array(
        'name' => __( 'Posts', 'buddypress' ),
        'slug' => 'user-posts',
        'position' => 19,
        'screen_function' => 'jv_user_posts', 
        'show_for_displayed_user' => true

  ) );

  bp_core_new_nav_item( array(
        'name' => __( 'Gallery', 'buddypress' ),
        'slug' => 'user-gallery',
        'position' => 20,
        'screen_function' => 'jv_user_gallery' 
  ) );

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

  // Remove a menu item
  $bp->bp_nav['activity'] = false;
  $bp->bp_nav['blogs'] = false;

  // Change name of menu item
  $bp->bp_nav['groups']['name'] = 'community';
 }
 add_action( 'bp_setup_nav', 'my_setup_nav' );

 // Load a page template
 function jv_user_posts() {
  bp_core_load_template( 'buddypress/bp/cst-user-posts' );
 }
 function jv_user_gallery() {
  bp_core_load_template( 'buddypress/bp/cst-user-gallery' );
 }

it has successfully created 2 tabs! works ok!

BUT it goes to own “cst-user-posts.php” page and “cst-user-gallery.php” page.

I mean I want to add them in /buddypress/members/sigle/home.php file

Then they will be below profile head part.

I guess the part is here on home.php

 <?php do_action( ‘bp_before_member_body’ );

 if ( bp_is_user_activity() || !bp_current_component() ) :
  bp_get_template_part( ‘members/single/activity’ );

 elseif ( bp_is_user_blogs() ) :
 bp_get_template_part( ‘members/single/blogs’ );

 elseif ( bp_is_user_friends() ) :
 bp_get_template_part( ‘members/single/friends’ );

 elseif ( bp_is_user_groups() ) :
 bp_get_template_part( ‘members/single/groups’ );

 elseif ( bp_is_user_messages() ) :
 bp_get_template_part( ‘members/single/messages’ );

 elseif ( bp_is_user_profile() ) :
 bp_get_template_part( ‘members/single/profile’ );

 elseif ( bp_is_user_forums() ) :
 bp_get_template_part( ‘members/single/forums’ );

 elseif ( bp_is_user_notifications() ) :
 bp_get_template_part( ‘members/single/notifications’ );

 elseif ( bp_is_user_settings() ) :
 bp_get_template_part( ‘members/single/settings’ );

 // If nothing sticks, load a generic template
 else :
 bp_get_template_part( ‘members/single/plugins’ );

 endif;

 do_action( ‘bp_after_member_body’ ); ?>

How can I make “if” condition for those 2 pages? I don’t know how to create “bp_is_user_posts” or “bp_is_user_posts” functions. if I could, I just need to add … if conditions.

I can't even fine "bp_is_user_profile()" these functions on bp files. how it works??

Please advice me!

Thanks, pulla

share|improve this question

closed as off-topic by Wyck, Pat J, kaiser Jul 30 at 19:08

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.

2 Answers 2

up vote 1 down vote accepted

Unless you're willing to create new components, it'll be easier and faster to inject content into members/single/plugins

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

function jv_user_posts_content() {
  echo "put content here";
}
share|improve this answer
    
Thanks for your quick response. what is this dir? "members/single/plugins" do I need to create? I don't have now. it shows members list. –  pulla Jun 1 at 2:31
    
I have searched some tutorial. I have found a tutorial to add sub tabs. it works fine and it's like what you just said. but for nav tab is not working. so your is not working. any tip? please try yours and see if mine is not working or not. –  pulla Jun 1 at 4:28
    
works fine... I don't know why.. I found another sample source and it's same as yours. but work! thank you so much. you saved my sunday :) –  pulla Jun 1 at 5:17

How to create a new tab in the Buddypress profile link with user posts?

1) create a folder /buddypress/ under your theme directory

2) create bp-custom.php file in the directory. Now your theme folder has a structure -->

your Theme Directory/buddypress/bp-custom.php

2.1 Include bp-custom.php file in your theme function.php using include or include_once php function.

3) create three actions to get the tab working(Don't do any thing yet. Just explaining the theory)

add_action( 'bp_setup_nav', 'buddyboss_child_bp_nav_adder' );
add_action( 'bp_template_content', 'profile_buddyboss_child_loop' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );

4) First you need to apply action buddyboss_child_bp_nav_adder to the hook bp_setup_nav.

5) The function definition looks like this.

    function buddyboss_child_bp_nav_adder() {
    global $bp;
    $post_count = count_user_posts_by_type( $bp->displayed_user->id );

    bp_core_new_nav_item(
      array(
        'name' => sprintf( __( 'Articles <span>%d</span>', 'my-poems' ), $post_count ),
        'slug' => 'Articles',
        'position' => 250,
        'show_for_displayed_user' => true,
        'screen_function' => 'buddyboss_child_list',
        'item_css_id' => 'articles',
        'default_subnav_slug' => 'public'
      ));
  }

6) The important part in the above function is screen_function with name buddyboss_child_list

7) create a function with name buddyboss_child_list

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

The important filters and functions are ..
buddy Press filter ===>>> bp_template_content
buddyPress function to load template =>>> bp_core_load_template

8) Declare and define a new function for content. In the above we have profile_buddyboss_child_loop function to fetch data.

/* This is end of the code for above function */
    function profile_buddyboss_child_loop() {
    $myposts = get_posts(  array(
      'posts_per_page' => -1,
      'author'         => bp_displayed_user_id(),
      'post_type'      => 'post'
    ));
    if( ! empty($myposts) ) { 

      foreach($myposts as $post) {
            setup_postdata( $post );
            if (has_post_thumbnail( $post->ID ) ):
                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'sidebar-smallthumbnew' );
            else :
                $image[0] = "http://placehold.it/85x60";
            endif;
            echo '<li class="sidebar mostpop post-' . $post->ID . '"><div id="postimage"><a href="' . get_permalink($post->ID) . '"><img src="' . $image[0] . '" /></a></div><div id="postinfo"><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></div></li>';
        }
        echo '</ul>';
        wp_reset_postdata();

     } else { ?>
    <div class="info" id="message">
         <p><strong><?php bp_displayed_user_fullname(); ?></strong> has No posts.</p>

    </div>
    <?php }
  }

  /* This is end of the code for above function */

9) To get no of posts by a author or user, used the below function in the

add_filter('bp_setup_nav','');
         function count_user_posts_by_type( $userid, $post_type = 'post' ) {
            global $wpdb;
            $where = get_posts_by_author_sql( $post_type, true, $userid, true);
            $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
            return apply_filters( 'get_usernumposts', $count, $userid );
    }

That's it. By this time your profile page shows the user/author page with their own posts.

share|improve this answer

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