- This topic has 14 replies, 2 voices, and was last updated 2 years, 6 months ago by
Tom.
-
AuthorPosts
-
April 16, 2019 at 10:28 pm #871122
Sebastien
Hi,
Is there a simple way to add a “show comments” toggle button on all my blog posts and pages please? Sometimes there are too many comments, and I just want to hide them unless the reader really wants to read them.
And thanks for this amazing theme, I am loving it so far!
Many thanks
sebastienGP Premium 1.7.8April 17, 2019 at 4:44 am #871350David
StaffCustomer SupportHi there,
the Volume Site has this toggle:
https://gpsites.co/volume/sample-post/
Is that something similar to what you need?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 17, 2019 at 4:51 am #871356Sebastien
Hi,
Thank you for your response. Yes this would work. How can I implement this in my theme please?
April 17, 2019 at 5:07 am #871370David
StaffCustomer SupportFirst you need to create a new Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Add this to the Hook Content:
<label class="switch"> <input type="checkbox" name="c1" onchange="showMe('comment-list', this)"/> <span class="slider"><!--toggle--></span> </label> <script> function showMe (it, box) { var vis = (box.checked) ? "none" : "block"; document.getElementsByClassName(it)[0].style.display = vis; } </script>
Select the
below_comments_title
hook.Set the display rules to Post > All Posts
Then this CSS:
/* Show Hide Comments Toggle */
.switch { position: relative; display: inline-block; width: 60px; height: 34px; } .switch input { display: none; } .slider, .slider:before, .slider:after { position: absolute; } .slider { cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; -webkit-transition: .4s; transition: .4s; border-radius: 34px; } .slider:before { content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; border-radius: 50%; z-index: 1 } .slider:after { content: "SHOW HIDE"; font-size: 0.4em; line-height: 34px; margin-left: 0.45em; color: #fff; letter-spacing: 0.05em; } input:checked+.slider:before { -webkit-transform: translateX(26px); transform: translateX(26px); }
To have the List hidden by default change this line in the HTML:
<input type="checkbox" name="c1" onchange="showMe('comment-list', this)"/>
to:
<input type="checkbox" name="c1" onchange="showMe('comment-list', this)" checked/>
And add this additional CSS:
.comment-list { display: none; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 17, 2019 at 5:13 am #871379Sebastien
Thank you David.
What hook am I adding this to excactly please? Is it hook after_content or before_comments?
Many thanks
sebastienApril 17, 2019 at 5:15 am #871381David
StaffCustomer SupportI edited the post above to include the Hook ( oops π )
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 17, 2019 at 5:33 am #871400Sebastien
Thank you, I had to tweak the css a bit but it is working well. How can I have the comments hidden by default please?
April 17, 2019 at 5:53 am #871418epickenyan
You can try this plugin too https://wordpress.org/plugins/lazy-load-for-comments/.
April 17, 2019 at 7:21 am #871628David
StaffCustomer SupportI edit this reply to include how to do set as checked by default:
https://generatepress.com/forums/topic/add-a-toggle-button-to-show-hide-comments/#post-871370
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 18, 2019 at 4:56 am #872424Sebastien
This is perfect! Thank you π
April 18, 2019 at 5:04 am #872428David
StaffCustomer SupportGlad to be of help
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 30, 2020 at 11:09 am #1263627Rogi
Hi David!
Thank you so much for sharing that hook. It is very useful.
Would it be possible to use this hook with a single button instead of a checkbox?
By clicking the button shows the comments and by clicking the button again hides the comments, and vice versa.
Thank you.
April 30, 2020 at 5:16 pm #1263985Tom
Lead DeveloperLead DeveloperHi there,
That would require javascript.
However, you can make a checkbox look like a button: http://jsfiddle.net/zAFND/2/
More info on the code here: https://stackoverflow.com/questions/7642277/css-styled-a-checkbox-to-look-like-a-button-is-there-a-hover
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentSeptember 12, 2020 at 11:06 am #1440802Mallory
Hi, I’m having troubles implementing this, when I add everything, the words “show comments” are slightly blocked by the toggle switch. Can I have the words just clickable with no toggle?
September 12, 2020 at 1:17 pm #1440872Tom
Lead DeveloperLead DeveloperHi there,
Can you link us to your website so we can take a look?
Thanks! π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.