Skip to:
Content
Pages
Categories
Search
Top
Bottom

Number of comments on that entry

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

  • Brajesh Singh
    Participant

    @sbrajesh

    Hi,
    You need to override this js function

    
     bp_legacy_theme_hide_comments(
    

    There are many ways to do it. You can either put the following code in your theme’s js file

    
    function bp_legacy_theme_hide_comments() {
    	var comments_divs = jq('div.activity-comments'),
    		parent_li, comment_lis, comment_count;
    	
    		var max_show = 2;
    	
    	if ( !comments_divs.length ) {
    		return false;
    	}
    
    	comments_divs.each( function() {
    		if ( jq(this).children('ul').children('li').length < max_show ) {
    			return;
    		}
    
    		comments_div = jq(this);
    		parent_li = comments_div.parents('#activity-stream > li');
    		comment_lis = jq(this).children('ul').children('li');
    		comment_count = ' ';
    
    		if ( jq('#' + parent_li.attr('id') + ' a.acomment-reply span').length ) {
    			comment_count = jq('#' + parent_li.attr('id') + ' a.acomment-reply span').html();
    		}
    
    		comment_lis.each( function(i) {
    			/* Show the latest 5 root comments */
    			if ( i < comment_lis.length - max_show ) {
    				jq(this).addClass('hidden');
    				jq(this).toggle();
    
    				if ( !i ) {
    					jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_x_comments.replace( '%d', comment_count ) + '</a></li>' );
    				}
    			}
    		});
    
    	});
    }
    
    

    or you can put the following php code in your bp-custom.php/functions.php

    
    
    function buddydev_override_legacy_theme_hide_comments_js() {
    	?>
    <script type="text/javascript">
    function bp_legacy_theme_hide_comments() {
    	var comments_divs = jq('div.activity-comments'),
    		parent_li, comment_lis, comment_count;
    	
    		var max_show = 2;
    	
    	if ( !comments_divs.length ) {
    		return false;
    	}
    
    	comments_divs.each( function() {
    		if ( jq(this).children('ul').children('li').length < max_show ) {
    			return;
    		}
    
    		comments_div = jq(this);
    		parent_li = comments_div.parents('#activity-stream > li');
    		comment_lis = jq(this).children('ul').children('li');
    		comment_count = ' ';
    
    		if ( jq('#' + parent_li.attr('id') + ' a.acomment-reply span').length ) {
    			comment_count = jq('#' + parent_li.attr('id') + ' a.acomment-reply span').html();
    		}
    
    		comment_lis.each( function(i) {
    			/* Show the latest 5 root comments */
    			if ( i < comment_lis.length - max_show ) {
    				jq(this).addClass('hidden');
    				jq(this).toggle();
    
    				if ( !i ) {
    					jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_x_comments.replace( '%d', comment_count ) + '</a></li>' );
    				}
    			}
    		});
    
    	});
    }
    
    </script>
    
    <?php
    	
    }
    add_action( 'bp_after_activity_loop', 'buddydev_override_legacy_theme_hide_comments_js' );
    
    

    Both will work. you can change the max_show to any value. Hope that helps.


    slawek247
    Participant

    @slawek247

    Hello again.

    Thank you very much, it helped me a lot and it works fine.
    But after click in “Load More” in bottom of page, older post has been loaded. Then thoses posts are loaded with all comments. Seems, the function bp_legacy_theme_hide_comments does not work for load more. Can you confirm it? Or maybe it’s a kind of bug, or maybe other other function is responsible for this? (I tried to find some other function but without success).

    Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Number of comments on that entry’ is closed to new replies.
Skip to toolbar