Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

how to have comment and replies collapse and expand. (71 posts)

Started 1 year, 2 months ago by: Aliceembroid

  • Profile picture of Aliceembroid Aliceembroid said 1 year, 2 months ago:

    I have buddypress with just one activity stream, I want to have it so that replies will be collapsed until a user clicks on it to read the threads. Can someone help me please?
    My page is very long and hard for people to find the comments they want to read.

    http://eembroiderydesigns.com/social/

  • Profile picture of Aliceembroid Aliceembroid said 1 year, 1 month ago:

    Does anyone have an answer?

  • Profile picture of Timothy Tarmon Jr Timothy Tarmon Jr said 1 year, 1 month ago:

    give me about an hour and i can get this working for you

  • Profile picture of Timothy Tarmon Jr Timothy Tarmon Jr said 1 year, 1 month ago:

    ok, break out notepad++ or any text editor and make back ups these two files:
    - /wp-content/plugins/buddypress/bp-themes/bp-default/activity/entry.php
    -/wp-content/plugins/buddypress/bp-themes/bp-default/header.php

    add this to your header.php file within the head section :

    <?php if ( !bp_is_activity_permalink() ) : ?>
    <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js "> </script>
    <?php endif; ?>

    now locate entry.php and replace : <div class="activity-comments">
    with this code :

    <?php if ( !bp_is_activity_permalink() && intval(bp_activity_get_comment_count()) !='0' ) : ?>
    <script type="text/javascript">
    $(document).ready(function(){
    
    		$("li#activity-<?php bp_activity_id() ?> div.activity-comments ul").hide();
    
    		$("li#activity-<?php bp_activity_id() ?> a.acomment-reply").click(function(){
                         if ( $("p.collapse-<?php bp_activity_id() ?>").css("display") == 'none' ){
    
    			$("p.expand-<?php bp_activity_id() ?>, p.collapse-<?php bp_activity_id() ?>, li#activity-<?php bp_activity_id() ?> div.activity-comments ul").toggle(100);
    
                            }
                           return true;
                        });
    
    		$("p.expand-<?php bp_activity_id() ?> a").click(function(){
    
    			$("p.expand-<?php bp_activity_id() ?>, p.collapse-<?php bp_activity_id() ?>, li#activity-<?php bp_activity_id() ?> div.activity-comments ul").toggle(100);
                       return false;
    
                    });
    
    		$("p.collapse-<?php bp_activity_id() ?> a").click(function(){
    
    			$("p.expand-<?php bp_activity_id() ?>, p.collapse-<?php bp_activity_id() ?>, li#activity-<?php bp_activity_id() ?> div.activity-comments ul").toggle(100);
                       return false;
    
                    });
    
                   $("li#activity-<?php bp_activity_id() ?> input[name=ac_form_submit]").click(function(){
    
                         if ( $("p.collapse-<?php bp_activity_id() ?>").css("display") == 'none' ){
    
    			$("p.expand-<?php bp_activity_id() ?>, p.collapse-<?php bp_activity_id() ?>, li#activity-<?php bp_activity_id() ?> div.activity-comments ul").toggle(100);
    
                            }
                         return true;
                    });
    
            });
    </script>
    		<div class="activity-comments">
                       <div class="expandable">
    
    	             <p class="expand-<?php bp_activity_id() ?>"><a href="#">Show Comments</a></p>
    
    	                 <p style="display:none" class="collapse-<?php bp_activity_id() ?>"><a href="#">Hide Comments</a></p>
    
                             </div>
    <?php else : ?>
    		<div class="activity-comments">
    <?php endif; ?>

    heres a little css to work with:

    .expandable {
        -moz-border-radius: 5px 5px 5px 5px;
        -webkit-border-radius: 5px 5px 5px 5px;
        background: none repeat scroll 0 0 #F4F6F8;
        border: 1px solid #EEEEEE;
        margin-bottom: 2px;
        text-align: center;
        text-shadow: 1px 1px 1px #FFFFFF;
    }
    
    .expandable p {
        margin: 0px;
    }

    remember to always back up your files, hopefully someone makes a plugin with this functionality so we can stop messing with the core of buddypress.

    *Can’t believe that took me 5 hours lol

  • Profile picture of James James said 1 year, 1 month ago:

    hi @timothyjunior nice update, definitely will try.
    messing with core files isn’t smth terrible, all you should have is child theme of bp-default.

  • Profile picture of Timothy Tarmon Jr Timothy Tarmon Jr said 1 year, 1 month ago:

    thanks @janismo, and you’re correct. If you have a child theme then it would be best to post to those files.
    I forgot about child themes when i took on this test. definitely something i should remember.

  • Profile picture of Aliceembroid Aliceembroid said 1 year, 1 month ago:

    Oh boy thank you so much, I had not checked back because I had lost hope that anyone would answer me. I am off to try it now. Thank you thank you thank you.

  • Profile picture of Aliceembroid Aliceembroid said 1 year, 1 month ago:

    That worked! you are a genius, the exception is that it does not collapse the comments on photos or newly registered members. But I guess that is a problem for another day. Thank you so much. check it out.

    http://eembroiderydesigns.com/social/

  • Profile picture of Aliceembroid Aliceembroid said 1 year, 1 month ago:

    Timothy, thank you so much, it is perfect now. I did not add the css. I was not sure where to add it. but I am so happy with how it is all working now.
    Alice.

  • Profile picture of josemv josemv said 1 year, 1 month ago:

    Nice, very nice, thanx @timothyjunior and @aliceembroid for sharing this.
    Now, how would I add a comments count field ? I mean, showing the comments count if there are any comments or showing nothing if there are not. Am I clear enough ?

  • Profile picture of Timothy Tarmon Jr Timothy Tarmon Jr said 1 year, 1 month ago:

    Glad its working now alice, and i think the css isn’t needed, but if you want to test it -> wp-content-> themes -> bp-columns ->custom.css
    What i usually do is scroll down to the very bottom and type this
    /* Custom Modifications */
    then my css code, to keep it separate from the default css

    where would you like to show the comments? Buddypress does this by default for logged in user via the reply link : reply(#comments).

  • Profile picture of josemv josemv said 1 year, 1 month ago:

    I can see on @aliceembroid site that it shows as “show comments”. I would like to have a comments count as “show comments (x)” being x the total number of comments.
    So each visitor can know at a first glance if that activty has any comments or not before pressing “show comments”

  • Profile picture of Timothy Tarmon Jr Timothy Tarmon Jr said 1 year, 1 month ago:

    that jquery code i supplied allows a “show comments” option only if the activity has comments, if the activity does not have comments it will show nothing.

    but i understand what you are saying, just replace:
    <a href="#">Show Comments</a>
    with this:
    <a href="#">Show Comments (<span><?php bp_activity_comment_count() ?></span>)</a>

  • Profile picture of Aliceembroid Aliceembroid said 1 year, 1 month ago:

    josemv you can see how many comments are there if you look at the reply button the yellow one on my site.
    Alice.

  • Profile picture of James James said 1 year, 1 month ago:

    hi again @timothyjunior ,

    - in your updated code for header.php you have typing mistake on the end of the 2nd line (closing script tag)
    - comments/replies of all the activities that go after load more button is pressed are already revealed/expanded and cannot be hidden. Is here any quick fix, or this is exactly what you wanted to achieve?

    thanks!