EXAMPLE: Javascript Accordion/CSS/Template
-
EXAMPLE: Javascript Accordion/CSS/Template
It’s been a long day… so I hope I get this correct here..
This is a bit “rough” but just here as an example..
And once again… I probably have some things wrong here… but as a basic example it should work for some or all of you.AS ALWAYS Precautionary to beginners make back ups of your database and your files…
1.) In your “header.php” or your child theme..
This must go in…
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
That calls the Ajax library that contains the Accordion..
Assuming you already have Posts displaying with this plugin…
In the Templates…
<ul id="purple"> [posts] <div id="accordion"> <li id="whitepurple" class="withborder"><div class="accordion-toggle" style="padding:1px;width:430px"> [post_thumbnail width="125" height="75"] <span style="background-color: #ffff00;"><strong>[post_title]</strong></span></div> <div class="accordion-content none" style="background-color: #ccffff;"> [excerpt wordlimit=20][more]</div> </li> [/posts]</ul> </div>
In the “Style” —> “Javascript Box”
<script type="text/javascript"> $(document).ready(function($) { $('#accordion').find('.accordion-toggle').click(function(){ //Expand or collapse this panel $(this).next().slideToggle('fast'); //Hide the other panels $(".accordion-content").not($(this).next()).slideUp('fast'); }); }); </script> <style> .accordion-toggle {cursor: pointer; margin: 0;} .accordion-content {display: none;} .accordion-content.default {display: block;} </style>
And then in the “Style” –> CSS Box..
.ul, #purple { border-radius: 10px/10px; -webkit-border-radius: 10px/10px; -moz-border-radius: 10px/10px; -ms-border-radius: 10px/10px; -o-border-radius: 10px/10px; background: #7220c9; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; box-shadow: 0 0 10px rgba(0,0,0,0.9); -webkit-box-shadow: 0 0 10px rgba(0,0,0,0.9); -moz-box-shadow: 0 0 10px rgba(0,0,0,0.9); -ms-box-shadow: 0 0 10px rgba(0,0,0,0.9); -o-box-shadow: 0 0 10px rgba(0,0,0,0.9); /* No borders set */ } .li, #whitepurple { color: black; /* text color is black */ font-family: Arial; font-size: 14px; background: white; /* Content, padding will be white */ border-radius: 10px/10px; -webkit-border-radius: 10px/10px; -moz-border-radius: 10px/10px; -ms-border-radius: 10px/10px; -o-border-radius: 10px/10px; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; list-style: none /* no glyphs before a list item */ /* No borders set */ } LI.withborder { border-radius: 10px/10px; -webkit-border-radius: 10px/10px; -moz-border-radius: 10px/10px; -ms-border-radius: 10px/10px; -o-border-radius: 10px/10px; border-style: none; border-width: medium; /* sets border width on all sides */ border-color: #27d130; }
PLEASE NOTE: This is just an example for beginners and a bit “rough” but is working with WordPress 4.0 and Twentyfourteen Theme.
I actually have it pretty nice using a couple of other plugin’s… but I just wanted to put up an example for Javascript…
AND I’m a just a beginner with a lot of this stuff so I know I have things incorrect but this is just an example that can be improved by others or to learn from for other beginners.ANOTHER NOTE: You can only have one instance of this Accordion Per Page… BUT if you change the Javascript for EACH “List” you can have multiple Accordions… that is…
For a second Accordion “List” on the same page this should work in the other “List”<script type="text/javascript"> $(document).ready(function($) { $('#accordion-2').find('.accordion-toggle-2').click(function(){ //Expand or collapse this panel $(this).next().slideToggle('fast'); //Hide the other panels $(".accordion-content-2").not($(this).next()).slideUp('fast'); }); }); </script> <style> .accordion-toggle-2 {cursor: pointer; margin: 0;} .accordion-content-2 {display: none;} .accordion-content.default {display: none;} </style>
AND then in the Template… add the different “-2” to the variables.. to reflect the “second” accordion…
HOPEFULLY I haven’t blundered this help file… But I have tested.
- The topic ‘EXAMPLE: Javascript Accordion/CSS/Template’ is closed to new replies.