Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to show comments only when I click on comment button ?


  • mahdiar
    Participant

    @mahdiar

    Hi
    I’d like to hide comments to activities and when user click on comments buttons shows the comment list like posting new comment .
    How can I do that ?
    I try some jquery codes but it failed .

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

  • danbp
    Moderator

    @danbp


    mahdiar
    Participant

    @mahdiar

    Thanks .
    I read those pages before . The first one is about 9 month ago and it is closed to new replies . I can’t find any solution there .
    The second one is about how to hide comments completely in activity stream but it’s nice to see them just by one click on the activities .


    danbp
    Moderator

    @danbp

    @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
    }

    mahdiar
    Participant

    @mahdiar

    Thanks a lot !
    -I tried jquery for the main comments button but it wasn’t worked . Is it possible ?
    -I just delete “.single-group” in style to make the comments hidden at first . Is it necessary ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to show comments only when I click on comment button ?’ is closed to new replies.
Skip to toolbar