BuddyPress support from our community
Limit # of items in the Activity Stream Loop?
February 16, 2012 at 6:23 am #1373
Does anyone know how to limit the number of initially loaded items in the activity stream? I have a heavy media sharing community which causes a slow page load on the activity stream. I’d like to limit the initially displayed entries to 5-10 from the default value of 20.
The BuddyPress Codex shares some info but does not go into great detail and my PHP skills are still a bit weak.
The parameter I am looking to use is ‘per_page’.
Only one filtering example is shown and I cannot figure out how one would take such an example, use the desired parameter and integrate it with the standard loop.
Any help would be appreciated.
DarinFebruary 16, 2012 at 3:04 pm #2355
@Darin– We have a custom activity stream on the front page of this site. Here’s some sample code. Essentially you need to write your own loop.
There may be an easier way with BP 1.5… This code was written before 1.5. was released.February 16, 2012 at 11:11 pm #2356
Thank you for this! This code snippet is definitely heading in the right direction. I works well for custom loops of latest entries as long as you do not need to load more, as on the main activity stream page. This is where I am trying to limit the output.
I’ll need to play with it a bit to get working the way I’d like. When I pass the arguments ( ‘per_page=5&page=1’ ) it returns only 5 items as expected, however, it returns the same 5 items every time I click ‘Load More’. I get the same result even if I remove the ‘page=1’ parameter since that is a default value.
I am working with the latest BP 1.5.4 so I am not sure if there were any significant changes to the activity since. I’ll keep searching and experimenting.
I appreciate the feedback and help!February 17, 2012 at 3:01 am #2357
Update: I received a simple answer on the BP forums.
Just in case anyone wants to limit their main Activity Stream Page, simply edit this line in your theme’s activity/activity-loop.php file:
if ( bp_has_activities( bp_ajax_querystring( ‘activity’ ) . ‘&per_page=5’ ) ) :
BTW: Are there any tags enabled here to display code?February 17, 2012 at 6:41 am #2358
@Darin– A small correction. Do NOT edit the main BuddyPress theme files.
-Make a child theme for BP
-copy the file activity/activity-loop.php and place it in your child theme, in a subdirectory called “activity”.
-Edit THAT file.
Yes, wrap your code inFebruary 17, 2012 at 11:03 am #2359
I am editing this awesome WP/BP theme (framework) Salutation, which includes customized copies of all BP default templates and folder structure, therefore, I am not touching the BP default theme or any core files.
It is certainly something important to remember, thanks for mentioning it.
I’ve spent a great deal of time figuring things out, which is great and helps my understanding. BuddyPress is a good theme development challenge. I definitely plan to learn PHP properly though, to speed up development time.
You must be logged in to reply to this topic.