Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Creating a tab that takes in the info from wp recent posts?

  • @splendorito

    Participant

    Hi,

    I want a custom tab in the profile that takes in the info from wp recents post? I have this code below that should do the job but I don’t understand how to hook it up with wp recent posts..

    //Buddypress add profile tab Latest Post
    add_action( 'bp_setup_nav', 'latest_post_nav' );
     
    function latest_post_nav() {
        global $bp;
        $parent_slug = 'Post';
        $child_slug = 'Post_sub';
        //name, slug, screen, position, default subnav
        bp_core_new_nav_item( 
                        array(
                                'name' => 'Posts',
                                'slug' => $parent_slug,
                                'screen_function' => 'my_profile_page_function_to_show_screen',
                                'position' => 50,
                                'default_subnav_slug' => $child_slug 
                        ) 
        );
    }
    function my_profile_page_function_to_show_screen() {
     
        //add title and content here – last is to call the members plugin.php template
        add_action( 'bp_template_title', 'my_profile_page_function_to_show_screen_title' );
        add_action( 'bp_template_content', 'my_profile_page_function_to_show_screen_content' );
        bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
     
    function my_profile_page_function_to_show_screen_title() {
        echo 'Page title';
    }
     
    function my_profile_page_function_to_show_screen_content() {
        echo 'Page content';
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • @splendorito

    Participant

    The person who can help me with this I give 15 bucks..

    @danbp

    Participant

    hi @splendorito,

    add these snippets into bp-custom.php or your child-theme functions.php

    The first one builds a new tab called Posts on the user’s profile page:

    // building the new tab
    function bpfr_post_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'post';
    	$child_slug = 'post_sub';
    	
    	bp_core_new_nav_item( array(
    	'name' => 'Posts',
    	'slug' => $parent_slug,
    	'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/',
    	'screen_function' => 'profile_page_show_screen',
    	'position' => 40,
    	'default_subnav_slug' => $child_slug 
    	) );
    	}
    	
    	function profile_page_show_screen() {	
    	add_action( 'bp_template_content', 'profile_post_page_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    	}
    	
    	function profile_post_page_screen_content() {
    		do_action( my_profile_post);
    	}	
    add_action( 'bp_setup_nav', 'bpfr_post_profile_setup_nav' );

    The second snippet display the user post on the new tab:

    function bpfr_get_post() {
    	
    	$myposts = get_posts(  array(
    	'posts_per_page' => 6, // set the number of post to show, -1 if all
    	'author'         => bp_displayed_user_id(),
    	'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
    			//echo '<a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a>';			
    			
    			// comment the 2 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">
    	<p><strong>'. bp_displayed_user_fullname() .'</strong> has No posts.</p>		
    	</div>';
    		}
    	}
    add_action ( 'my_profile_post', 'bpfr_get_post' );

    Tested with bp 2.0.2 / WP 4.0 on twenty thirteen

    @splendorito

    Participant

    @danbp, the first part works perfectly. But the second don’t on my theme.. also I must remind you that I don’t want something like myposts, where only my articles are shown. I have already a plugin for that. I want that the everything published from the blog is fetched to that tab for every user.

    Can you please help..

    @splendorito

    Participant

    heh.. it works, this made it to not work > / uncomment next line to show only a list of titles linked to full post

    @splendorito

    Participant

    It’s made for myposts as thought..I want everybody to access the latest post.

    @danbp

    Participant

    @splendorito,

    comment just the line ‘author’ in the 2nd widget.

    Here a slightly rewamped version, with a sub nav tab.

    function bpfr_get_post() {
    	
    	/*
    	 * to get all post, comment the line 'author'
    	 */
    	$myposts = get_posts(  array(
    	'posts_per_page' => 3, // 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>';			
    			
    			/*
    			 * 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_post', 'bpfr_get_post' );
    
    function bpfr_post_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'posts';
    	$child_slug = 'posts_sub';	
    	
    	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' );

    @splendorito

    Participant

    Nice, do you have skype @danbp?

    @danbp

    Participant

    i have a buddypress community: http://bp-fr.net. You can contact me there.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Creating a tab that takes in the info from wp recent posts?’ is closed to new replies.
Skip to toolbar