Change ‘Show all X comments’ limit
-
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 5Hi 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.
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:667I 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 ?
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!
Custom code for BP is generaly added to bp-custom.php.
Thanks! Just as a follow up. I just copy and paste that code into that file? Anywhere better than any other?
Yes, copy/paste, no matter where in that file.
Thanks @danbp for that toggle snippet, nearly five and a half years later and still works a treat!
Two questions if I may:
1 Is it possible to default to hidden?
2 Is it possible to move the button to another position?
I’m testing Youzify which may complicate things as it appears where I want to move it to is behind a Youzify component that only appears once a comment has been posted.
From what I understand (which in coding is very little sadly) your code searches for the “Comment” button and inserts the toggle button after it:
$(this).find('.button.acomment-reply').after(html);
I tried modifying that line in your code to target the Youzify component which has a div class of “youzify-post-comments-count”, but alas, no joy.
$(this).find('.youzify-post-comments-count').after(html);
Any pointers would be much appreciated.
Regards
Edit: image doesn’t appear to be showing but can be seen here https://www.awesomescreenshot.com/image/18924495?key=fdf218d488bb16129f5baeb43949ba6b
- You must be logged in to reply to this topic.
graeme_bryson
@graeme_bryson
8 years, 5 months ago
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