Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change ‘Show all X comments’ limit


  • graeme_bryson
    Participant

    @graeme_bryson

    I’m currently trying to bring the number of comments shown below a post from 5 to 2. I’ve updated the following lines in ‘global.js’, but the feed still outputs 5 comments below each activity item.

    (global.js line 1490)
    if ( jq(this).children('ul').children('li').length < 5 ) return;
    to
    if ( jq(this).children('ul').children('li').length < 2 ) return;

    (global.js line 1502)
    if ( i < comment_lis.length - 5 ) {
    to
    if ( i < comment_lis.length - 2 ) {

    I’m running a vanilla install of BuddyPress 2.6.1.1 on WP 4.5.3, so I’m assuming my logic is incorrect in how I’m trying to bring the comment count down. Any help would be massively appreciated as I’ve hit a bit of a brick wall.

    Cheers, Graeme

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

  • danbp
    Moderator

    @danbp

    No need to play with JS.
    BP follows the number of comments you fix in WP Settings > Discussion >
    Other comments: Enable threaded (nested) comments [5] levels deep // default is 5


    graeme_bryson
    Participant

    @graeme_bryson

    Hi Dan,

    I’ve perhaps described the situation poorly: I’m actually referring to the link above activity-item comments which states ‘Show all X comments’. On click, it reveals all additional comments beyond the intial five. I’ve attached a quick screenshot to clarify.

    https://www.dropbox.com/s/g8s26v9sw4lejc8/bp_comments.png?dl=0

    From past posts, I’ve gathered that others have updated ‘global.js’ (as above) to increase/decrease this threshold, but I’ve had no success with this method.

    @danbp


    danbp
    Moderator

    @danbp

    Global.js is related to BP Default theme which is no more used since 1.9.
    The “new” js you can check for comment count is \buddypress\bp-templates\bp-legacy\js\buddypress.js:667

    I don’t know how the default 5 count is set before firing Show all X comments link. But i haven’t read very attentively the whole js file.

    If your goal is to gain some place on activity feeds, you may use a show/hide comment button ?

    function add_comment_hide_show() {
    ?>
    <style>
    .single-group .activity-comments ul{display: none;}
    </style>
    <script type="text/javascript">
    jQuery(function($) {
    	setInterval(function() {
    		$('.activity-meta').each(function() {
    			if( !$(this).find('.show-comments').length ){
    				var html = '<a href="#" class="button bp-primary-action show-comments">Show/Hide Comments</a>';
    				$(this).find('.button.acomment-reply').after(html);
    			}
    		});
    		
    	}, 500);
    	
    	$('body').on('click', '.show-comments', function(e) {
    		e.preventDefault();
    		var obj = $(this).closest('.activity-content').next('.activity-comments').find('ul');
    		obj.slideToggle();
    		return false;
    	});
    	
    });
    </script>
    <?php
    }
    add_action( 'wp_footer', 'add_comment_hide_show' );

    Or if you want to limit the number of comment a member can leave on activities, BPDEVEL has a premium plugin called BP Rate Limit User Activity which can do that.

    On Trac, some very old tickets about comments: #2768, #1870

    Perhaps @dcavins can tell you more about this ?


    allanmisner
    Participant

    @allanmisner

    Danbp, How and where do I put that code you posted to create a show/hide comment button? Bear in mind I’m a BuddyPress noob and I’m no where near being a coder. Thanks!


    danbp
    Moderator

    @danbp

    Custom code for BP is generaly added to bp-custom.php.


    allanmisner
    Participant

    @allanmisner

    Thanks! Just as a follow up. I just copy and paste that code into that file? Anywhere better than any other?


    danbp
    Moderator

    @danbp

    Yes, copy/paste, no matter where in that file.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar