"Read more" button
-
Hi Armin!
In a page of my site I have a long text and I wish it was fully visible only when you click a "Read more" button.
I first tried a pair of plug-in (Wp show more, Collapse-O-Matic), but they didn't work because the inclusion of texts in Lay Theme is different from the classic mode of Wordpress themes.
So I tried to insert a button through the codes, and the only system that seems to work is this:
https://codepen.io/devkick/pen/soJpyHTML and CSS parts work well, but I can't integrate the Js part. I paste the Js code in "Custom <head> content", in a script tag and put "JQuery" instead of "$", but it still does not work.
Original script:
$(".readmore").on('click touchstart', function(event) {
var txt = $(".more-content").is(':visible') ? 'Show more (+)' : 'Less (–)';
$(this).parent().prev(".more-content").toggleClass("visible");
$(this).html(txt);
event.preventDefault();
});My version:
<script>
jQuery(".readmore").on('click touchstart', function(event) {
var txt = jQuery(".more-content").is(':visible') ? 'Show more (+)' : 'Less (–)';
jQuery(this).parent().prev(".more-content").toggleClass("visible");
jQuery(this).html(txt);
event.preventDefault();
});
</script>My page: http://fabrizioinglese.com/bio-di-prova
Did I do something wrong?
Is there another way to insert the button?I hope you give me a solution!
Thanks for the help and for the theme,Marta
-
Hey Marta sorry for my late response. As written here http://laytheme.com/documentation.html#binding-click-events you need to bind clicks a bit differently.
<script> jQuery(document).on("click touchstart", ".readmore", function(event) { var txt = jQuery(".more-content").is(':visible') ? 'Show more (+)' : 'Less (–)'; jQuery(this).parent().prev(".more-content").toggleClass("visible"); jQuery(this).html(txt); event.preventDefault(); }); </script> -
-
Merry Christmas to you too :)
-
Merry Christmas to you too :)
@arminunruh Dear Armin,
Lay Theme is awesome.Is there today a possibility for a "read more" button?
The Link is invalid, unfortunately.Best regards
-
yo just use the new "accordion" feature:
https://www.instagram.com/p/ClBAFnUD-tG/ -
yo just use the new "accordion" feature:
https://www.instagram.com/p/ClBAFnUD-tG/@arminunruh Best video ever! thx
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login