Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display “X” number of comments with read more option


  • dagamachris
    Participant

    @dagamachris

    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
    }

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