Skip to:
Content
Pages
Categories
Search
Top
Bottom

Calling a post authors activity stream


  • UrbanFix
    Participant

    @urbanfix

    Basically, I would like to call the activity stream of an author of a page.
    I know i would need to use the get_the_author_meta and call in the activity loop but i can’t seem to wrap my head around calling the loop and using the user id as a filter.
    any help would be appreciated!

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @urbanfix

    Here’s the standard loop taken from here.

    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?>
        <?php while ( bp_activities() ) : bp_the_activity(); ?>
     
            <?php locate_template( array( 'activity/entry.php' ), true, false ); ?>
     
        <?php endwhile; ?>
    <?php endif; ?>

    If you scroll down the page and take a look at filtering options, you’ll see user_id. So your loop will look something like this:

    $post = get_post( get_the_ID() );
    $filter = '&user_id=' . $post->post_author;
    
    if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . $filter ) ) :
        while ( bp_activities() ) : bp_the_activity();
            locate_template( array( 'activity/entry.php' ), true, false );
        endwhile;
    endif;

    Note: I haven’t tested.

    Caveat: This must be used within The Loop.


    UrbanFix
    Participant

    @urbanfix

    I do not have a clue what i’m doing if im honest,
    this is the code i have to create a new tab, how would i add the above code to this?
    Thanks


    danbp
    Moderator

    @danbp

    hi @urbanfix,

    please use the code button if you insert code or use an external service like pastebin or github and post the link to the snippet…

    What do you exactly try to built ?
    You first asked about page author’s activity, and now you want to create a tab.


    UrbanFix
    Participant

    @urbanfix

    Sorry I thought I had!

    This is code I have created to add a new tab to a cpt, its on

    <?php add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ;
    
    function geodir_detail_page_tab_list_extend($tab_array)
    {
     	$tab_array['my_new_tab'] = array( 
    										'heading_text' =>  __('New Tab',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'my_new_tab'),
    										'tab_content' => ''
    									);
    	return $tab_array ;
    }
    add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content');
    function geodir_my_new_tab_content($tab_index)
    {
    	if($tab_index =='my_new_tab')
    	{
    		echo "Hello world!!";
    	}
    }
    ?>

    These pages/cpts are created by buddypress users. So, on this new tab i have created i wish to call the activity stream of the author!
    My php knowledge is almost nill so I am really struggling, I didn’t think it was to hard a thing to do!


    UrbanFix
    Participant

    @urbanfix

    the link i added seems to of vanished, the new tab is on the following page;

    http://urban-fix.co.uk/food_and_drink/united-kingdom/merseyside/liverpool/bar/chameleon-bar-liverpool/#my_new_tab


    @mcuk
    Participant

    @mcuk

    Following this convo as I’m trying to add a customised activity stream to a new tab myself. Reading the above links by Henry atm…


    UrbanFix
    Participant

    @urbanfix

    The code im using to add a new tab isnt to add one to buddypress,
    If this is what you are after it is done in a different way look at;

    https://buddypress.org/support/topic/how-do-i-add-a-menu-item-on-the-profile-page/

    or subnav

    https://buddypress.org/support/topic/adding-a-subnav-with-new-page-content-to-the-profileactivity-page/


    @mcuk
    Participant

    @mcuk

    Yeah I’ve used the code below already to add the tab to the Buddybar (subnav tab in my case) in the required location. It’s the attempt to call/load the necessary page templates/functions and whatever else is required for the Activity Loop that I’m looking to do atm.

    // Add a new subnav menu tab 
    function new_subnav_tab() {
    	global $bp;
    	$parent_slug = 'notifications';
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name'            => __( 'Fave' ), 
    	'slug'            => fave, 
    	'parent_url'      => $bp->loggedin_user->domain . $parent_slug.'/', 
    	'parent_slug'     => $parent_slug, 
    	'screen_function' => '????',
    	'position'        => 30,
    	) );
    }
    add_action( 'bp_setup_nav', 'new_subnav_tab' );

    UrbanFix
    Participant

    @urbanfix

    Same here!
    I dont understand how the activty loop works, ive been trying to do this for 2 days now haha,
    If you get it working please let me know!


    @mcuk
    Participant

    @mcuk

    haha, I’ll take your 2 days and raise you another 3!

    If i get anywhere I will defo post it here. Haven’t found anything on the forums that’s helped so far (at least anything that I recognise as being a solution). I’m fairly new to php. Been through the plugin files and found a number of functions which are likely being used (not 100%), but just not able to call them to the new tab I’ve created.

    Currently working through reading Henry’s links above on the WordPress Codex and will have a fiddle around.


    danbp
    Moderator

    @danbp

    OMG !

    @urbanfix
    , you have warnings due to wrong geodirectory usage. Repair it !

    @mcuk
    please don’t hijack. Open your own topic as you’re not looking on exactly for the same thing.

    Try from this usage example.

    This code builds a tab, fetch an activity type content (here author post) and show it on a template part.

    function bpfr_post_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'extraposts';
    	$child_slug = 'posts_sub';	
    	
    	bp_core_new_nav_item( array(
    	'name' => __( 'Extra 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 extras' ), 
    	'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_stuff() {
    
       $activity_id = bp_activity_get_activity_id( array(
        'user_id' => $post->post_author,
        'type' => 'new_blog_post', // the activity type you want to show. See in activity table
        'component' => 'blogs',
        'item_id' => 1,
        'secondary_item_id' => $post->ID
       ) );
    	
    	if ( ! $activity_id ) {
    		return '';
    	}
    // this is the activity loop, with some options.
    	if ( bp_has_activities( $activity_id . '&action=activity_update&max=5' )  ) :
    		while ( bp_activities() ) : bp_the_activity();
    
    			bp_get_template_part( 'activity/entry');
    
    		endwhile;
    	endif;
    }
    
    add_action ( 'my_profile_post', 'bpfr_get_stuff' ); 

    Note that this is only an example and most probably the best way to do it.

    There is a little plugin which will be more handy eventually, which allows you to use shortcodes to get activities.

    If you add to plugin’s generate_activity_stream function these two lines

    $temp_post = get_post($post_id);
    $user_id = $temp_post->post_author;

    and change user_id in filtering to 'user_id' => $user_id, you’re able to get about anything for the given author, directly on the post page.

    May this help !


    @mcuk
    Participant

    @mcuk

    Hi @danbp,

    Sorry I thought I was looking for the same thing? Wasn’t aware that I was hijacking as a result. Won’t happen again 🙂


    danbp
    Moderator

    @danbp

    No worry. It’s just difficult to follow when a huge amount of snippets must be read to understand what each one does.

    I answered also to your other topic. Happy testing !


    UrbanFix
    Participant

    @urbanfix

    @danbp do you mean the grey warnings? they are gone now!
    I think I havent explained this very well, I already have the code which adds the tab (its a tab on a page not bp profile), i just cant work out what code i need to use to add the page authors activity stream to this tab?
    Thankyou


    Henry Wright
    Moderator

    @henrywright

    Was my suggestion any use?

    Basically, I would like to call the activity stream of an author of a page.

    I understood that to mean “Output an activity loop on a WordPress page limited to activity items belonging to the page author”.

    If my understanding is wrong, then please let me know.


    UrbanFix
    Participant

    @urbanfix

    @henrywright
    that is kind of what i’m trying to do,
    I have very little knowledge of php, and an awful lacking in how all this works!
    On my website bp users add things called ‘listings’ on these listings are a set of tabs.
    See this link:
    http://urban-fix.co.uk/food_and_drink/united-kingdom/merseyside/liverpool/bar/level-nightclub/#my_new_tab

    I have created a new tab in my functions.php using this code:

    <?php add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ;
    
    function geodir_detail_page_tab_list_extend($tab_array)
    {
     	$tab_array['my_new_tab'] = array( 
    										'heading_text' =>  __('New Tab',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'my_new_tab'),
    										'tab_content' => ''
    									);
    	return $tab_array ;
    }
    add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content');
    function geodir_my_new_tab_content($tab_index)
    {
    	if($tab_index =='my_new_tab')
    	{
    		echo "Hello world!!";
    	}
    }
    ?>

    On this tab I wish to display the activity stream of the bp user who created the listing,
    I didn’t realise it was going to be so complex (or just so hard…)
    Is this something someone could take the time to write for me? I can’t be the first person to want to do this!

    If i could get the activity stream to show on the tab i believe i could work the filters out, but i don’t, i either get a blank space or i create errors!


    danbp
    Moderator

    @danbp

    Have you tried to use the shortcode plugin i mentionned previously ?


    UrbanFix
    Participant

    @urbanfix

    I do not wish to use a plugin due to the current page load times and I have had a lot of issues with conflicts..
    If their is no other way i shall give up and try the plugin, but i have faith yet!


    UrbanFix
    Participant

    @urbanfix

    @danbp
    I have attempted to use the ‘little plugin’ you mentioned but when I add the following two lines i get an error! COuld you please add them for me?

    $temp_post = get_post($post_id);
    $user_id = $temp_post->post_author;

    I have sucessfully changed the user id as you mentioned without any trouble.

    public function generate_activity_stream( $atts, $content = null, ) {
            //allow to use all those args awesome!
           $atts=shortcode_atts(array(
                'title'            => 'Latest Activity',//title of the section
                'pagination'       => 'true',//show or not
                'display_comments' => 'threaded',
                'include'          => false,     // pass an activity_id or string of IDs comma-separated
                'exclude'          => false,     // pass an activity_id or string of IDs comma-separated
                'in'               => false,     // comma-separated list or array of activity IDs among which to search
                'sort'             => 'DESC',    // sort DESC or ASC
                'page'             => 1,         // which page to load
                'per_page'         => 5,         //how many per page
                'max'              => false,     // max number to return
    
                // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
                'scope'            => false,
    
                // Filtering
                'user_id'          => $user_id,    // user_id to filter on
                'object'           => false,    // object to filter on e.g. groups, profile, status, friends
                'action'           => false,    // action to filter on e.g. activity_update, new_forum_post, profile_updated
                'primary_id'       => false,    // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
                'secondary_id'     => false,    // secondary object ID to filter on e.g. a post_id
    
                // Searching
                'search_terms'     => false,         // specify terms to search on
                'use_compat'       => bp_use_theme_compat_with_current_theme() 
            ), $atts );
           
            extract( $atts );
    	
          
            
            ob_start(); ?>

    Thanks,
    Urban-fix


    danbp
    Moderator

    @danbp

    public function generate_activity_stream( $atts, $content = null, ) {
    
    $temp_post = get_post($post_id);
    $user_id = $temp_post->post_author;
    
     //allow to use all those args awesome!
           $atts=shortcode_atts(array(
    
             // rest of the function
    

    UrbanFix
    Participant

    @urbanfix

    This is perfect! Thanks @danbp!
    I got it to work!!

Viewing 21 replies - 1 through 21 (of 21 total)
  • The topic ‘Calling a post authors activity stream’ is closed to new replies.
Skip to toolbar