Skip to:
Content
Pages
Categories
Search
Top
Bottom

Modify the activity loop


  • deshmukh
    Participant

    @deshmukh

    I want to modify the activity loop so that

    • it includes postings from private/ hidden groups joined by the member (currently the activity page shows postings in public groups only)
    • recency is determined by the last comment on a post. So, a post made three weeks back but with a comment today comes on top (this also does not happen currently)

    How can I do that? If not example.com/activity loop, is there a way to add another loop or modify any other loop/ page to achieve this?

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

  • deshmukh
    Participant

    @deshmukh

    Any ideas here?


    Henry Wright
    Moderator

    @henrywright

    Hi @deshmukh

    • You can add items to the activity stream using bp_activity_add(). You’d write a custom function and hook it to the relevant action which fires when a group message has been posted (see a)
    • The display_comments parameter will help you here. You’ll need to change threaded to stream (see b)

    Refs:

    a) https://codex.buddypress.org/developer/function-examples/bp_activity_add/

    b) https://codex.buddypress.org/developer/loops-reference/the-activity-stream-loop/


    deshmukh
    Participant

    @deshmukh

    @henrywright I do not want to ‘add’ new activity. I just want that when one visits example.com/activity, it displays all profile updates (these are displayed even now), all updates to public groups (these, too, are displayed currently) AND all updates in private/ hidden groups where the concerned person is a member (this is NOT displayed currently.) How do I do that?

    Also, I understood the second part re threads with new comments coming to top. But could you please elaborate a bit? Do I need to add some code to bp-custom.php or mytheme/function.php? In this specific case, what code should I add?

    I am sorry if my question appear to be basic. I am a newbie — I like to guess, like many others coming to forums 🙂


    Henry Wright
    Moderator

    @henrywright

    I do not want to ‘add’ new activity. I just want that when one visits example.com/activity, it displays… …all updates in private/ hidden groups where the concerned person is a member (this is NOT displayed currently.) How do I do that?

    You have to ‘add’ the new activity.

    Regarding the second bullet point, you’d need to modify your activity loop which will be inside your activity template. Try something like this:

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

    For more info on the BuddyPress template system and where you find your activity template, please see this article.


    deshmukh
    Participant

    @deshmukh

    @henrywright Thanks! Here is what I did:

    edited /wp-content/plugin/buddypress/bp-activity/activity-template.php

    Found the activity loop and changed $defaults = array(
    ‘display_comments’ => ‘stream’

    That puts all comments on the top but only the comments are pulled to the top. What I really wanted was the entire conversation is pulled to the top.

    Also, I think what I have done is crude and somehow, not ‘proper’. For instance, when I update buddypress plugin, all my changes will be gone.

    How do I make sure that the changes remain?

    Also, I have gone through https://codex.buddypress.org/developer/function-examples/bp_activity_add/

    But still am nebulous about:
    You can add items to the activity stream using bp_activity_add(). You’d write a custom function and hook it to the relevant action which fires when a group message has been posted (see a)

    Can you elaborate?

    Lastly, the codex page talks about adding new activity to database. I hope, it makes sure that one gets to see messages posted to only those groups one is authorized to see.

    PS – When I crack it, is there any way I can contribute to the codex so other newbies like me have access to the stuff? How?

    Thanks!


    Henry Wright
    Moderator

    @henrywright

    /wp-content/plugin/buddypress/bp-activity/activity-template.php is a core file and you are indeed right to think that any changes you make will be overwritten when you upgrade the plugin.

    As I mentioned earlier, you should modify your activity template (sorry for not being clearer). The link I provided (to the BuddyPress Template Hierarchy) explains how you can create your own templates.

    To explain what I meant about bp_activity_add(), you’d write your own function which contains a call to bp_activity_add(). bp_activity_add() will add an item to the activity stream for you. Hooks are a feature of WordPress, you can read more about them here. You’d hook your custom function to a particular action which will result in bp_activity_add() executing at exactly the time you need it to.

    Hooks take a bit of getting your head around at first, but once you master them you’ll see how powerful they can be.

    PS – When I crack it, is there any way I can contribute to the codex so other newbies like me have access to the stuff? How?

    Sure you can! See the Participate and Contribute article for info on how you can help improve BP documentation.

    Hope all this info helps! Give me a shout if you need any further help


    deshmukh
    Participant

    @deshmukh

    @henrywright, this is going to be one long conversation, I guess. And thanks for your patience.

    OK. Went through the Codex page again. And, as I understood it, created mytheme/buddypress/activity/single/index.php with the code you had given earlier: ‘display_comments’ => ‘stream’. No effect.

    Then I copied the whole bp-activity-template.php to the same location, renamed it as index.php and changed ‘display_comments’ => ‘stream’. Still no effect.

    Obviously, I am doing something wrong. How do I get this right?

    Also, note my earlier point. This change, when successful, only pulls the comments up — not the entire conversation on which the comment was made. But that was the effect I wanted. How do I get that achieved?

    Lastly, I guess, I will need to make similar changes to other areas (display of group activity /members/username/activity/groups, favorites /members/username/activity/favorites — to be specific) or it is the same activity loop that generates those pages, too and changes at one place will reflect through all loops?


    deshmukh
    Participant

    @deshmukh

    Here is an update. I tried doing the same thing but changed directory to mytheme/buddypress/activity/index-directory.php with disastrous consequenes. With the code you had mentioned, it leads to a blank page and with bp-activity-template.php suitably renamed and modified, it gives an error.

    So, I guess, I will need to have the file in /mytheme/buddypress/activity and the name will need to be index-directory.php. But what goes in that file is still not known 🙂


    deshmukh
    Participant

    @deshmukh

    Any help here? I feel so near yet so far!


    Henry Wright
    Moderator

    @henrywright

    Take a look through the template files here to see how things fit together. If you use the Template Hierarchy article as a starting block (read through that first), the way you should organise your templates should become clearer

    Hope that helps?


    danbp
    Moderator

    @danbp

    Give this a try (functions.phhp or better, bp-custom.php) This will force the chronology of the blog post.

    Since recently (1.9 ?), a post published the 5th january is in the SWA at this date. A comment added to it the 26 january is attached to this post and appears under the 5th swa log…. so it’s just impossible to see if you have a long SWA.

    This snippet revert the swa to the previous behave.
    Posted: 5th -> swa: 5th
    Commented: 26th -> 26th

    function bpfr_stream( $qs, $object ) {
    	if ( 'activity' != $object ) {
    		return $qs;
    	}
    	
    	$qs = wp_parse_args( $qs, array() );
    	
    	$qs['display_comments'] = 'stream';
    	
    	return $qs;
    }
    add_filter( 'bp_ajax_querystring', 'bpfr_stream', 20, 2 );

    Private groups activities are not visible on the SWA. They show only on that group, if user is member and logged in.

    Hope that helps? 😉


    deshmukh
    Participant

    @deshmukh

    @danbp Thanks! That helped me move to ‘display_comments’ => ‘stream’ without touching the buddypress core files! 🙂

    But that is not what I meant. This is going to be a lengthy reply. So, please bear with me.

    Chronology of events:
    1 Jan – Status update of Member A
    2 Jan – Status update of Member B
    3 Jan – Comment on Status update of Member A.

    Default behaviour — SWA appears as:
    – Status update of Member B of 2 Jan
    – Status update of Member A of 1 Jan
    – Comment of Jan 3 on Status update of Member A of Jan 1

    Modified SWA With your suggested function:
    – Comment of Jan 3 on Status update of Member A
    – Status update of Member B of Jan 2
    – Status update of Member A of Jan 1

    How I wanted it:
    – Status update of Member A of Jan 1
    – Comment of Jan 3 on Status update of Member A
    – Status update of Member B of Jan 2

    Any way to get this?

    By the way, on a side note, in my view, that is the most logical way of a reverse chronological sequence. Whenever an activity happens about a post like a comment, that entire conversation becomes a new conversation.

    Still, so so near yet so far. If you don’t mind a bit of mathematics, its lim n -> 1


    deshmukh
    Participant

    @deshmukh

    @danbp this is intentionally another reply. Again, this is likely to be lengthy. So, please bear with me.

    Consider member1 is a member of private group PGA, and public group GB.

    site.com/activity includes updates in GB, and updates by other members.
    members/member1/activity/groups/ includes updates in PGA and GB.

    I wanted to merge the two — without duplicating content from GB. Any way to achieve that? Its perfectly OK if we can get that feed at site.com/activity or some other URL.

    On a side note, the advantages are:
    An one place, member1 gets to see ALL updates (whether private or public) AND we avoid duplication (GB is displayed both at site.com/activity and members/member1/activity/groups).


    danbp
    Moderator

    @danbp

    In fact i only responded to your second question by the last comment on a post.

    What you want to do is more complicated, and honestly, i’m not the right man to help you for such deep modification. Sorry for that.


    deshmukh
    Participant

    @deshmukh

    @henrywright, I looked at the files at the github link provided by you. But no luck. Did not get it at all. Please see the last two comments made by me above. Any help you can offer would be greatly appreciated.


    swatitiwariit90
    Participant

    @swatitiwariit90

    Thnx @danbp.. 🙂 it helped me..


    navinachettri
    Participant

    @navinachettri

    why dont you try BuddyPress Activity Stream Bump to Top plugin

Viewing 17 replies - 1 through 17 (of 17 total)
  • The topic ‘Modify the activity loop’ is closed to new replies.
Skip to toolbar