Skip to:
Content
Pages
Categories
Search
Top
Bottom

My Contributions Tab with Subtabs


  • 3T_MJ
    Participant

    @3t_mj

    I’d like to display the latest Posts, Images and Videos posted by a User in Subtabs of My Contributions tab in the profile of each member. Images and Videos are both custom post types.

    I found an example how to set up a Tab with a single subtab. I got this working:
    https://buddypress.org/support/topic/creating-a-custom-tab-that-takes-in-the-info-from-wp-recent-posts/
    But I’m stuck how to add the custom post types images and videos in seperate sub tabs. These should be displayed as thumbnails. Not sure how to achieve this. I tried to copy the given code for a second sub tab but what happens then that all the latest posts disappear and only the latest images of the current logedin member get displayed in the subtab, not the images of the specfici author. So I must be doing something completely wrong.

    That’s what I tried:`

    function bpfr_get_post() {
    	
    	/*
    	 * to get all post, comment the line 'author'
    	 */
    	$myposts = get_posts(  array(
    	'posts_per_page' => 25, // 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 );
    			$page_object = get_post( $post );			
    			
    			/* 
    			 * uncomment next line to show only a list of titles linked to full post
    			 * if you uncomment, you have to comment the 2 echo below
    			 */
    			
    		echo '<a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a><br />';			
    			
    			/*
    			 * comment the 2 following echo (or remove them) if you use the above
    			 */
    			
    		 // echo '<h3 class="profile_post">'. $page_object->post_title .'</h3>';
    		 // echo $page_object->post_content;
    		}	
    		
    		wp_reset_postdata();	
    	} else { 
    		
    		echo '<div class="info" id="message">No post to show actually.</div>';
    	}
    }
    add_action ( 'my_profile_posts', 'bpfr_get_post' );
    
    function bpfr_get_image() {
    	$myimages = get_posts(  array(
    	'posts_per_page' => 25, // set the number of post to show
    	'author'         => bp_displayed_user_id(), // show only this member post
    	'post_type'      => 'image',
    	'orderby'          => 'post_date',
    	'order'            => 'DESC',
    	'post_status'      => 'publish'
    	));
    	
    	if( ! empty( $myimages ) ) { 
    		
    		foreach($myimages as $post) {
    			setup_postdata( $post );
    			$page_object = get_post( $post );			
    			
    			/* 
    			 * uncomment next line to show only a list of titles linked to full post
    			 * if you uncomment, you have to comment the 2 echo below
    			 */
    			
    		echo '<a title="' . get_the_title($post->ID) . '" href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, 'thumbnail') . '</a>';			
    			
    			
    		}	
    		
    		wp_reset_postdata();	
    	} else { 
    		
    		echo '<div class="info" id="message">No images to show actually.</div>';
    	}
    }
    add_action ( 'my_profile_image', 'bpfr_get_image' );
    
    function bpfr_post_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'posts';
    	$child_slug = 'posts_sub';
    	$child_slug2 = 'images_sub';	
    	
    	bp_core_new_nav_item( array(
    	'name' => __( 'My contributions' ),
    	'slug' => $parent_slug,
    	'screen_function' => 'bpfr_profile_post_screen',
    	'position' => 50,
    	'default_subnav_slug' => $child_slug 
    	) );
    	
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name' => __( 'Latest posts' ), 
    	'slug' => $child_slug, 
    	'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/', 
    	'parent_slug' => $parent_slug, 
    	'screen_function' => 'bpfr_profile_post_screen'
    	) );
    
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name' => __( 'Latest images' ), 
    	'slug' => $child_slug2, 
    	'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/', 
    	'parent_slug' => $parent_slug, 
    	'screen_function' => 'bpfr_profile_image_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);
    }
    
    function bpfr_profile_image_screen() {	
    	add_action( 'bp_template_content', 'bpfr_profile_image_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function bpfr_profile_image_screen_content() {
    	do_action( my_profile_image);
    }
    
    add_action( 'bp_setup_nav', 'bpfr_post_profile_setup_nav' );

    I’m really new to this, so please forgive me if I’m asking help for something that might be obvious for anyone else. I really would appreciate if someone could guide me to a solution. Thanks a lot!

Viewing 3 replies - 1 through 3 (of 3 total)

  • 3T_MJ
    Participant

    @3t_mj

    I’m still stuck. I am able to generate main tabs showing the content I want but I don’t know how to maike this work having a common main tab and showing the content in sub tabs of the main tab.

    That’s the code for the main tabs that’s working for me:

    function bpfr_get_post() {
    	
    	/*
    	 * to get all post, comment the line 'author'
    	 */
    	$myposts = get_posts(  array(
    	'posts_per_page' => 25, // 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 );
    			$page_object = get_post( $post );			
    			
    			/* 
    			 * uncomment next line to show only a list of titles linked to full post
    			 * if you uncomment, you have to comment the 2 echo below
    			 */
    			
    		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>';			
    			
    			/*
    			 * comment the 2 following echo (or remove them) if you use the above
    			 */
    			
    		 // echo '<h3 class="profile_post">'. $page_object->post_title .'</h3>';
    		 // echo $page_object->post_content;
    		}
    
    		
    		wp_reset_postdata();	
    
    	} else { 
    		
    		echo '<div class="info" id="message">No posts to show actually.</div>';
    	}
    }
    add_action ( 'my_profile_post', 'bpfr_get_post' );
    
    function bpfr_post_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'contributions';
    	$child_slug = 'posts';	
    	
    	bp_core_new_nav_item( array(
    	'name' => __( 'Posts' ),
    	'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' => __( 'Latest posts' ), 
    	'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' );
    
    function bpfr_get_image() {
    	
    	/*
    	 * to get all post, comment the line 'author'
    	 */
    	$myimages = get_posts(  array(
    	'posts_per_page' => 25, // set the number of post to show
    	'author'         => bp_displayed_user_id(), // show only this member post
    	'post_type'      => 'image',
    	'orderby'          => 'post_date',
    	'order'            => 'DESC',
    	'post_status'      => 'publish'
    	));
    	
    	if( ! empty( $myimages ) ) { 
    		
    		foreach($myimages as $post) {
    			setup_postdata( $post );
    			$page_object = get_post( $post );			
    			
    			/* 
    			 * uncomment next line to show only a list of titles linked to full post
    			 * if you uncomment, you have to comment the 2 echo below
    			 */
    			
    		echo '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, array( 75, 75)) . '</a>';			
    			
    			/*
    			 * comment the 2 following echo (or remove them) if you use the above
    			 */
    			
    		 // echo '<h3 class="profile_post">'. $page_object->post_title .'</h3>';
    		 // echo $page_object->post_content;
    		}	
    		
    		wp_reset_postdata();	
    	} else { 
    		
    		echo '<div class="info" id="message">No images to show actually.</div>';
    	}
    }
    add_action ( 'my_profile_image', 'bpfr_get_image' );
    
    function bpfr_image_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'images';
    	$child_slug = 'images_sub';	
    	
    	bp_core_new_nav_item( array(
    	'name' => __( 'Images' ),
    	'slug' => $parent_slug,
    	'screen_function' => 'bpfr_profile_image_screen',
    	'position' => 50,
    	'default_subnav_slug' => $child_slug 
    	) );
    	
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name' => __( 'Latest Images' ), 
    	'slug' => $child_slug, 
    	'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/', 
    	'parent_slug' => $parent_slug, 
    	'screen_function' => 'bpfr_profile_image_screen'
    	) );
    }
    
    function bpfr_profile_image_screen() {	
    	add_action( 'bp_template_content', 'bpfr_profile_image_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function bpfr_profile_image_screen_content() {
    	do_action( my_profile_image);
    }
    
    add_action( 'bp_setup_nav', 'bpfr_image_profile_setup_nav' );

    Hope someone can help me.


    danbp
    Participant

    @danbp

    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' );

    3T_MJ
    Participant

    @3t_mj

    Sorry for my late reply. It works perfectly.

    Not sure if it is possible but is there a way to show all published posts and make it paginated instead of showing only a certain number of postst?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘My Contributions Tab with Subtabs’ is closed to new replies.
Skip to toolbar