Reply To: My Contributions Tab with Subtabs
Here it is, some general idea.
// building navigation tabs
function bpfr_post_profile_setup_nav() {
global $bp;
$parent_slug = 'contributions';
$child_slug = 'posts';
// main nav
bp_core_new_nav_item( array(
'name' => __( 'Contributions' ),
'slug' => $parent_slug,
'screen_function' => 'bpfr_profile_post_screen',
'position' => 40,
'default_subnav_slug' => $child_slug
) );
// Add subnav item 1
bp_core_new_subnav_item( array(
'name' => __( 'My posts' ),
'slug' => $child_slug,
'parent_url' => $bp->displayed_user->domain . $parent_slug.'/',
'parent_slug' => $parent_slug,
'screen_function' => 'bpfr_profile_post_screen'
) );
// Add subnav item 2
bp_core_new_subnav_item( array(
'name' => __( 'My Pictures' ),
'slug' => 'pics',
'parent_url' => $bp->displayed_user->domain . $parent_slug.'/',
'parent_slug' => $parent_slug,
'screen_function' => 'bpfr_profile_picture_screen'
) );
// Add subnav item 3
bp_core_new_subnav_item( array(
'name' => __( 'My Videos' ),
'slug' => 'vids',
'parent_url' => $bp->displayed_user->domain . $parent_slug.'/',
'parent_slug' => $parent_slug,
'screen_function' => 'bpfr_profile_video_screen'
) );
}
// calling templates
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_picture_screen() {
add_action( 'bp_template_content', 'bpfr_profile_picture_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
function bpfr_profile_video_screen() {
add_action( 'bp_template_content', 'bpfr_profile_video_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
// adding action hooks to template
function bpfr_profile_post_screen_content() {
do_action( my_profile_post);
}
function bpfr_profile_picture_screen_content() {
do_action( my_profile_pictures);
}
function bpfr_profile_video_screen_content() {
do_action( my_profile_videos);
}
add_action( 'bp_setup_nav', 'bpfr_post_profile_setup_nav' );
// fetching content
function bpfr_get_post() {
$myposts = get_posts( array(
'posts_per_page' => 6, // set the number of post to show
'author' => bp_displayed_user_id(), // show only this member post
'post_type' => 'post',
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish'
));
if( ! empty( $myposts ) ) {
foreach($myposts as $post) {
setup_postdata( $post );
$post_object = get_post( $post );
echo '<div>
<div class="tab-item-thumbnail" style="float:left;padding-right:5px;"><a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, array( 25, 25) ) . '</a></div>
<div class="tab-item-inner group">
<p><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></p>
</div>
</div>';
}
wp_reset_postdata();
} else {
echo '<div class="info" id="message">No post.</div>';
}
}
add_action ( 'my_profile_post', 'bpfr_get_post' );
function bpfr_get_pictures() {
$myposts = get_posts( array(
'posts_per_page' => 6,
'author' => bp_displayed_user_id(),
'post_type' => 'post', // post_type key
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish'
));
if( ! empty( $myposts ) ) {
foreach($myposts as $post) {
setup_postdata( $post );
/* here we catch featured image attached to each post
* using get_the_post_thumbnail()
*/
echo '<div class="tab-item-thumbnail" style="float:left;padding-right:5px;"><a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, array( 150, 150) ) . '</a></div>';
}
wp_reset_postdata();
} else {
echo '<div class="info" id="message">No picture.</div>';
}
}
add_action ( 'my_profile_pictures', 'bpfr_get_pictures' );
function bpfr_get_videos() {
echo 'Page is empty, add your content !';
}
add_action ( 'my_profile_videos', 'bpfr_get_videos' );