Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'add_comment_hide_show'

Viewing 10 results - 1 through 10 (of 10 total)
  • Author
    Search Results
  • #312369
    chris98
    Participant

    Hello,

    I have included the following code, to show and hide the comments, but how I can show and hide the add new Comment textbox too? Actually, I can only show the add new Comment textbox, and if I click on the 1 Comment, the textbox doesnt hide, but the other comments hide.

    add_action( 'wp_footer', 'add_comment_hide_show' );
    function add_comment_hide_show() {
        ?>
        <style>
            .activity-comments ul li[id^="acomment-"]{display: none;}
        </style>
        <script type="text/javascript">
            jQuery(function($) {
                setInterval(function() {
                    $('.activity-meta').each(function() {
                        if( !$(this).find('.comments-count').length ){
                            var html = '<a href="#" class="button bp-primary-action comments-count"></a>';
                            $(this).find('.button.acomment-reply').after(html);
                        }
                    });
    
                }, 500);
    
                $('body').on('click', '.comments-count', function(e) {
                    e.preventDefault();
                    var obj = $(this).closest('.activity-content').next('.activity-comments').find('ul li[id^="acomment-"]');
                    obj.slideToggle();
                    return false;
                });
    
            });
        </script>
    #310161
    Anonymous User 17603124
    Inactive

    Hi,
    I found the code to hide comments in the activity stream. Adds an additional button (show / hide comments)
    How can I add the number of comments for the current post?

    I have something like that made by @shay1383

    add_action( 'wp_footer', 'add_comment_hide_show' );
    function add_comment_hide_show() {
        ?>
        <style>
            .activity-comments ul li[id^="acomment-"]{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 li[id^="acomment-"]');
                    obj.slideToggle();
                    return false;
                });
    
            });
        </script>
        <?php
    }

    For comments button, the number of commentators is displayed by:
    <a href="<?php bp_activity_comment_link(); ?>" class="button acomment-reply bp-primary-action" id="acomment-comment-<?php bp_activity_id(); ?>"><?php printf( __( 'Comment %s', 'buddypress' ), '<span>' . bp_activity_get_comment_count() . '</span>' ); ?></a>

    But if I use it, the same number of comments appear under each post. How to make it work?

    dagamachris
    Participant

    Hi,

    Wordpress 5.2.2, Buddypress 4.3.0 Reign theme from Wbcom http://www.tipua.com

    I’ve got this code to hide comments by default with a show/hide option on each activity update, and it’s working fine on my staging site. Ideally though I’d like to display 3 comments by default with a read more option. I’ve read that BP uses a WP config to set the number of comments displayed initially, but the posts I’ve read seem to indicate that was on older versions. Is there a configuration I can set to show the number of comments by default, (In which case I could dispense with the code module) or do I need to modify this code. If the latter, any guidance would be greatly appreciated.

    Thanks
    Chris

    add_action( ‘wp_footer’, ‘add_comment_hide_show’ );
    function add_comment_hide_show() {
    ?>
    <style>
    .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 = ‘Show/Hide‘;
    $(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
    }

    #265358
    shay1383
    Participant

    sorry, copy that one:

    add_action( 'wp_footer', 'add_comment_hide_show' );
    function add_comment_hide_show() {
        ?>
        <style>
            .activity-comments ul li[id^="acomment-"]{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 li[id^="acomment-"]');
                    obj.slideToggle();
                    return false;
                });
    
            });
        </script>
        <?php
    }
    #265357
    shay1383
    Participant

    add_action( ‘wp_footer’, ‘add_comment_hide_show’ );
    function add_comment_hide_show() {
    ?>
    <style>
    .activity-comments ul li[id^=”acomment-“]{display: none;}
    </style>
    <script type=”text/javascript”>
    jQuery(function($) {
    setInterval(function() {
    $(‘.activity-meta’).each(function() {
    if( !$(this).find(‘.show-comments’).length ){
    var html = ‘Show/Hide Comments‘;
    $(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 li[id^=”acomment-“]’);
    obj.slideToggle();
    return false;
    });

    });
    </script>
    <?php
    }

    #256489
    danbp
    Participant

    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 ?

    #254884

    In reply to: Lock comments button

    danbp
    Participant
    silvep4
    Participant

    I am interested in “Show/Hide Comments” and I found the following code for that :

    add_action( 'wp_footer', 'add_comment_hide_show' );
    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
    }

    And it is working good when I add it to functions.php but the problem is that by default it shows all the comments and it hides the comments when we click on the “Show/Hide Comments” button. Can anybody edit it so that by default it hides the comments and when we click on the button then it shows the comments.

    Thanks.

    chatty24
    Participant

    Alternatively, I am also interested in “Show/Hide Comments” and I found the following code for that : –

    add_action( 'wp_footer', 'add_comment_hide_show' );
    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
    }

    And it is working good when I add it to functions.php but the problem is that by default it shows all the comments and it hides the comments when we click on the “Show/Hide Comments” button. Can anybody edit it so that by default it hides the comments and when we click on the button then it shows the comments.

    Thanks.

    #215656
    danbp
    Participant

    @mahdiar,

    here’s a working snipppet found on WPMUDev which add a show/hide comments button above each activity item.

    To see the button you must enable “allow blog and forum comments” in BP settings.
    Add the script to bp-custom.php or child theme functions.php

    add_action( 'wp_footer', 'add_comment_hide_show' );
    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
    }
Viewing 10 results - 1 through 10 (of 10 total)
Skip to toolbar