Reduce number of statuses (statii?) on Activity stream

Yo team,

This is another really dumb question: where can I restrict the number of activity statuses on each page? Strikes me that rather than having it default to 20 or so that it would be better with 10 to speed up page load? No?

Peace,

Andrew.

  • Arun Basil Lal
    • New Recruit

    Hey Andrew,

    There is nothing called a dumb question, there are questions and then there are questions :wink:

    This is a popular one, here is the solution you need:
    http://wpnyc.org/groups/buddypress-troubleshooting-and-support/forum/topic/limit-of-items-in-the-activity-stream-loop#post-887

    Basically find the activity/activity-loop.php file on the BuddyPress theme folder and edit this line:

    if ( bp_has_activities( bp_ajax_querystring( ‘activity’ ) . ‘&per_page=5? ) ) :

    Change 5 to any number you like.

    I would recommend that you include this in a child theme so that you wont loose it over the next BuddyPress update.

    See how you can make one:
    http://codex.buddypress.org/theme-development/building-a-buddypress-child-theme/

    Let me know if you get stuck, would be glad to help you further :slight_smile:

  • Andrew Shanahan
    • Site Builder, Child of Zeus

    Yo Arun - thanks mate, top notch advice as always.

    In my theme I've tracked down activity-loop and it has this:

    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?>

    <?php /* Show pagination if JS is not enabled, since the "Load More" link will do nothing */ ?>
    <noscript>
    <div class="pagination">
    <div class="pag-count"><?php bp_activity_pagination_count(); ?></div>
    <div class="pagination-links"><?php bp_activity_pagination_links(); ?></div>
    </div>
    </noscript>

    So should I just add in ‘&per_page=5? before the final bracket?

  • Jack Kitterhing
    • Code Norris

    Hi there!

    I'm not too sure about the soundmanager 2 errors, I don't quite get that, but it works fine for me, this is my file, with the edit added, (if you want just copy it, it doesn't have any other custom code in it)

    <?php
    
    /**
     * BuddyPress - Activity Loop
     *
     * Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter()
     *
     * @package BuddyPress
     * @subpackage bp-default
     */
    
    ?>
    
    <?php do_action( 'bp_before_activity_loop' ); ?>
    
    <?php if ( bp_has_activities( bp_ajax_querystring( ‘activity’ ) . ‘&per_page=5? ) ) : ?>
    
    	<?php /* Show pagination if JS is not enabled, since the "Load More" link will do nothing */ ?>
    	<noscript>
    		<div class="pagination">
    			<div class="pag-count"><?php bp_activity_pagination_count(); ?></div>
    			<div class="pagination-links"><?php bp_activity_pagination_links(); ?></div>
    		</div>
    	</noscript>
    
    	<?php if ( empty( $_POST['page'] ) ) : ?>
    
    		<ul id="activity-stream" class="activity-list item-list">
    
    	<?php endif; ?>
    
    	<?php while ( bp_activities() ) : bp_the_activity(); ?>
    
    		<?php locate_template( array( 'activity/entry.php' ), true, false ); ?>
    
    	<?php endwhile; ?>
    
    	<?php if ( bp_activity_has_more_items() ) : ?>
    
    		<li class="load-more">
    			<a href="#more"><?php _e( 'Load More', 'buddypress' ); ?></a>
    		</li>
    
    	<?php endif; ?>
    
    	<?php if ( empty( $_POST['page'] ) ) : ?>
    
    		</ul>
    
    	<?php endif; ?>
    
    <?php else : ?>
    
    	<div id="message" class="info">
    		<p><?php _e( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ); ?></p>
    	</div>
    
    <?php endif; ?>
    
    <?php do_action( 'bp_after_activity_loop' ); ?>
    
    <form action="" name="activity-loop-form" id="activity-loop-form" method="post">
    
    	<?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ); ?>
    
    </form>

    Hope this helps.

    Kind Regards
    Coding-Monkey.

  • Andrew Shanahan
    • Site Builder, Child of Zeus

    Hi Coding Monkey - thanks for the code but again if I change that line to the one you've got I get a Sound Manager error - see screengrab. This is what I have for Activity Loop

    <?php
    
    /**
     * BuddyPress - Activity Loop
     *
     * Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter()
     *
     * @package BuddyPress
     * @subpackage bp-default
     */
    
    ?>
    
    <?php do_action( 'bp_before_activity_loop' ); ?>
    
    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?>
    
    	<?php /* Show pagination if JS is not enabled, since the &quot;Load More&quot; link will do nothing */ ?>
    	<noscript>
    		<div class=&quot;pagination&quot;>
    			<div class=&quot;pag-count&quot;><?php bp_activity_pagination_count(); ?></div>
    			<div class=&quot;pagination-links&quot;><?php bp_activity_pagination_links(); ?></div>
    		</div>
    	</noscript>
    
    	<?php if ( empty( $_POST['page'] ) ) : ?>
    
    		<ul id=&quot;activity-stream&quot; class=&quot;activity-list item-list&quot;>
    
    	<?php endif; ?>
    
    	<?php while ( bp_activities() ) : bp_the_activity(); ?>
    
    		<?php locate_template( array( 'activity/entry.php' ), true, false ); ?>
    
    	<?php endwhile; ?>
    
    	<?php if ( bp_activity_has_more_items() ) : ?>
    
    		<li class=&quot;load-more&quot;>
    			<a href=&quot;#more&quot;><?php _e( 'Load More', 'cc' ); ?></a>
    		</li>
    
    	<?php endif; ?>
    
    	<?php if ( empty( $_POST['page'] ) ) : ?>
    
    		</ul>
    
    	<?php endif; ?>
    
    <?php else : ?>
    
    	<div id=&quot;message&quot; class=&quot;info&quot;>
    		<p><?php _e( 'Sorry, there was no activity found. Please try a different filter.', 'cc' ); ?></p>
    	</div>
    
    <?php endif; ?>
    
    <?php do_action( 'bp_after_activity_loop' ); ?>
    
    <form action=&quot;&quot; name=&quot;activity-loop-form&quot; id=&quot;activity-loop-form&quot; method=&quot;post&quot;>
    
    	<?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ); ?>
    
    </form>

    I'm using the Custom Community Pro theme. Any chance you could tell me where to amend that so I can just show a limited number (say 5) statuses?

  • aecnu
    • WP Unicorn

    Greetings Andrew,

    It has been brought to my attention that this ticket should be moved to the Advanced WordPress Discussion section to better serve you and to get more senior/experienced programmers to look into this custom coding and to hopefully get you a quick resolution thereof.

    Cheers, Joe

  • Andrew Shanahan
    • Site Builder, Child of Zeus

    Thanks Joe - all sorted. The code was great but actually the reason I was reducing statuses was because it was running kind of slow. Turned out that the load on the VPS we use was a tad over weight. We've upgraded now and it's all running smoothly (for now...). Thanks for the help chaps.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.