Home Forums Weaver Xtreme Theme Collapse comment section

This topic contains 15 replies, has 2 voices, and was last updated by  scrambler 2 months ago.

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #60035

    guigui
    Participant

    Hi,

     

    I’m trying to make the comment section of every posts and pages hidden when the page loads. But have a button that opens the comments when clicked.
    To rephrase it, I’d like to have the comment section of the post collapsed, until the visitor click on a button like “show comments”.

    There’s a post saying it’s possible with Collapse-o-matic ( This plugin lets you wrap any content in a collapsible div.) and providing the code to make it.

    But the post is not noob-proof. The instruction says:

    Collapsible comments – Replace comment area with something like the following:

    (followed by the code that you can see on the first example of the post). I don’t understand where and what code I should replace with the code provided.

     

    Can you please tell me where I should paste this code in my child theme? I guess it’s somewhere in a template file of Weaver Xtreme? Or maybe in functions.php? Or maybe in one of the custom CSS menus of Weaver settings?

    I tried several things but can’t make it work. Here is the test site where I’m trying to make it.

     

    Thanks

    #60037

    scrambler
    Moderator

    These changes require knowledge of PHP and WordPress coding as well as the creation of a child theme.

    The child theme allows you to modify the PHP template of the theme by your own, with the necessary changes in HTML and PHP.

    If you are not fluent in both, it is probably not for you 🙂

    You may want to contact the plugin developer to see if they could help.

    #60039

    guigui
    Participant

    Thanks for the answer!

    I know how to use a child theme. But no knowledge in PHP or wordpres coding. So I guess I’ll give up or try to find another solution to hide the comments.

    #60041

    scrambler
    Moderator

    I had a look at the Weaver Xtreme templates.

    the comment template is called

    comments.php

    If you copy that in your child theme, you can try editing that template to include the proper classes mentioned by the plugin and see if that works.

    I think the template create the comments div with the line

    echo '<div id="comments">';

    So you can try editing that to make it

    echo '<div id="comments">';
    echo '<div id="commentCollapse" class="collapseomatic">';
    So it adds a new div with the classes and ID the plugin needs
    Then you need to edit the line that closes the div to also close the new added one.
    echo "</div><!-- #comments -->\n";
    And change it to
    echo "</div></div><!-- #comments -->\n";

     

    #60055

    guigui
    Participant

    Thank you very much!

    I had no problem at all to follow your instructions.

    And it kinda works. The comment section is totally hidden. But There is no button to display it at all. 🙂
    Maybe that’s something to setup in Collapse-o-matic settings. Or maybe something to custom from the code provided here (1. Collapsible comments). But I haven’t figured it out yet. I asked for help on their forum but no answer yet.

    Here is the test website where I’m trying to make it work.

    #60057

    scrambler
    Moderator

    I am not sure what you did, because if I inspect the page of a single post

    https://guigui82.yo.fr/wp/2019/01/30/post-n90/

    The comment section is not there instead of being there with the modification described above.

    You may have messed up something in the PHP modifications, making the template invalid and simply not loading.

    Deactivate the child theme and post back so I can have a look at the post page when the modification is not in there.

     

    NOTE: When you edited the PHP template, I hope you did not copy paste from the forum as that usually messes up the quotes.

    If you did start again from the original template and do the modifications manually, triple checking the syntax.

    #60059

    scrambler
    Moderator

    OK So I looked a little further, and you also need to add the open close content like below

    <span class="collapseomatic" title="comments" id="monkey1" >OPEN COMMENTS</span>
    <span id="swap-commenst" style="display: none;">CLOSE COMMENTS</span>
    
    

    And I think I had the class for the content wrong so try this instead:

    Change

    echo '<div id="comments">';

    to the one below with the modified classes

    echo '<div id="comments">';
    echo '<div id="target-collapsecomments" class="collapseomatic_content">';

    Then

    The line I told you to modifiy to become
    echo "</div></div><!-- #comments -->\n";
    should become
    echo "</div></div><!-- #comments -->\n";
    echo "<span class="collapseomatic" title="comments" id="collapsecomments" >OPEN COMMENTS</span>";
    echo "<span id="swap-collapsecomments" style="display: none;">CLOSE COMMENTS</span>";
    #60072

    guigui
    Participant

    Hi! Sorry for the delay.

    Indeed I copy/pasted the code from the forum at first.

    But I just deleted and typed everything manually on my comments.php in my child theme.
    I also typed manually the code you provided and tripled checked everything. I found a small typo in your code. (swap-commenst), that I did not reproduce 🙂

    The comments do appear normally if I comment out/delete the code provided on the collapse-o-matic forum. But as soon I put it back, the comments don’t appear anymore.
    So I guess there is something wrong with their code.

    I just re-enabled the Weaver Xtreme parent theme. So that you can check that the comments work without this code.

    Finally, I pasted my child comments.php on pastebin in case it could help you show me if I messed up something. 🙂

    #60076

    scrambler
    Moderator

    You appear to have added two sets of code in there, both the one you picked up on that forum and the changes I gave you. Line 25 to 42 I believe.

    You need to start from the original template and ONLY do the modifications I gave you.

    The code you picked up from the forum have nothing to do in there.

    
    
    #60092

    guigui
    Participant

    Oh, OK. Thanks. 🙂

    I restarted from the original comments.php and only added the code you provided. But still the comments section doesn’t appear under the posts. You can check my new comments.php here.

     

    Maybe I put the open close content lines at the wrong spot? I just put them at the begginning (lines 25-26).

    #60095

    scrambler
    Moderator

    You really need to pay attention to what you are doing here…

    You still have two rogue lines (25 and 26 below)

    1. <span class="collapseomatic" title="comments" id="monkey1" >OPEN COMMENTS</span>
    2.     <span id="swap-comments" style="display: none;">CLOSE COMMENTS</span>

    Which means you did NOT start from scratch like I told you…

     

    ALSO:

    I noticed I had an error in the last two lines I gave you (some double quotes need to be single to avoid mixup with the content).

    These

    echo "span class="collapseomatic" title="comments" id="collapsecomments" >OPEN COMMENTS</span>";
    
    echo "<span id="swap-collapsecomments" style="display: none;">CLOSE COMMENTS</span>";

     

    Should be (changes in yellow, do not paste, type to make sure quotes are correct)

    echo 'span class="collapseomatic" title="comments" id="collapsecomments" >OPEN COMMENTS</span>';
    
    echo '<span id="swap-collapsecomments" style="display: none;">CLOSE COMMENTS</span>';
    #60530

    guigui
    Participant

    Thanks.

    I’m sorry. There’s a missunderstanding from my part. When you said:

     you also need to add the open close content like below

    in post #60059,  I thought that meant I HAD to add the two lines below in comments.php. That’s why they were here (lines 26-26). But now you say they are rogue lines. I don’t get it (So they shouldn’t be added?). Sorry. I’m not a native english speaker. So some stuff might me above my understandding. But I DID start from scratch and typed manually every lines you kindly quoted to me.

    #60534

    scrambler
    Moderator

    Sorry, when I said to add the lines, I meant using the method described aftwerwards

    I am trying to post a summary of the changes again to be clear, but for some reason the forum does allow me to post the PHP anymore.

    I will keep trying and if I cant post the PHP we will have to wait until @weaver comes back

    #60535

    scrambler
    Moderator
    Summary, below are the only changes to try on the template.
    Change
    echo '<div id="comments">';
    
    
    to the one below
    echo '<div id="comments">';
    echo '<div id="target-collapsecomments" class="collapseomatic_content">';
    
    
    Then the existing line 
    echo "</div><!-- #comments -->\n";
    
    
    should be changed to
    echo "</div></div><!-- #comments -->\n";
    echo '<span class="collapseomatic" title="comments" id="collapsecomments" >OPEN COMMENTS</span>';
    echo '<span id="swap-collapsecomments" style="display: none;">CLOSE COMMENTS</span>';
    #60560

    guigui
    Participant

    It’s working!

    Thank you so much for your patience!

    #60561

    scrambler
    Moderator

    I am amazed it did 🙂

Viewing 16 posts - 1 through 16 (of 16 total)

You must be logged in to reply to this topic.