Skip to:
Content
Pages
Categories
Search
Top
Bottom

get_comment_count()


  • Anonymous User 17603124
    Inactive

    @anonymized-17603124

    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?

  • You must be logged in to reply to this topic.
Skip to toolbar