How To Customize The BuddyPress Activity Loop
The BuddyPress activity loop shows every kind of BuddyPress activity by default. However, the activity loop wasn’t meant to be a one-size-fits-all arrangement. In fact, the BuddyPress core developers have made it possible for you to filter the loop using a number of specified parameters.
You might be surprised by how many ways there are to customize the activity loop. Here’s a quick list of what’s possible, as outlined in the BuddyPress codex:
- Filter activities based on scope – Show only activity for the scope you pass, ie. just-me, friends, groups, favorites, mentions
- Turn comments off and/or change display – none, threaded, stream
- Include certain activity items – uses activity_id or string of comma-separated ids to show only these entries
- Sort the stream chronologically – ASC, DESC
- Set the number of activity items to show per page – per_page – default value: 20
- Limit activity items to a specific user ID – user_id – false (default), true
- Filter for a specific component – groups, friends, profile, status, blogs
This is only a sampling. There are many other less-common ways detailed in the codex for filtering and manipulating the activity stream.
How To Edit The Activity Loop
The file you’re looking for is located in the /activity/ folder in your BuddyPress theme. Locate activity/activity-loop.php. We’ll use the default theme as an example. Of course, you should probably create a child theme to keep your changes separate.
How to Remove Activities Related to the Friends Component
For this example, we’re going to remove updates from the friends component. Here’s a screenshot of the activity stream before we customize the loop:
Now, in order to remove activities related to the friends component, we need to specify all of the other components we want to show and omit the friends component, like so:
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&object=groups,profile,status,blogs' ) ) : ?>
Here’s a screenshot of the final resulting activity stream with no updates from the friends component:
How to Remove New Member and New Avatar Updates From the Activity Stream
Let’s try another example. If you feel that updates about new members and members changing their profile pictures clutters up the activity stream, here’s how you can remove those updates:
FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.
FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&object=groups,friends,status,blogs' ) ) : ?>
How to Limit the Activity Stream to a Certain Number of Updates
Want to keep the activity stream short and sweet? Use “max=” to set a number of activities to return:
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&max=5' ) ) : ?>
How to Display Activity Related to a Search Term
Let’s say you want to create a custom activity loop page that shows all activity related to a specific search term. In this example, we’ll use the ‘nap’ as our search term. Perhaps we want to call this page “People talking about naps” and include any related activity. Here’s how you would do that:
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&search_terms=nap' ) ) : ?>
The resulting activity stream would look something like this:
How to Limit the Activity Stream to Friends Only
Showing activity update for friends only is a customization that’s often requested. All you have to do is add ‘scope=friends’. After all, this is the default way for many other social networks that users have participated in prior to joining your BuddyPress site. For this example, let’s also limit it to show only activity updates as well. Here’s how to do that:
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ).'&scope=friends&action=activity_update' ) ) : ?>
The resulting loop shows only friends’ activity updates, as pictured above.
As you can see, there’s quite a lot you can do to make the activity stream more useful for your members. The BuddyPress codex only gives a couple of examples, so hopefully, these listed above will help you get started creating your own custom activity loops.
Tags: