Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created December 6, 2017 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leepettijohn/a95ad58364e1ea18865fc273b44ef135 to your computer and use it in GitHub Desktop.
Save leepettijohn/a95ad58364e1ea18865fc273b44ef135 to your computer and use it in GitHub Desktop.
WordPress custom toggle on Archive Loop
<?php
/* *** add the below code to the page where all the information that should be displayed in the Loop */
/* *** this is the link to click */ ?>
<a class="more-info-link <?php tribe_events_event_classes() ?>" style="cursor:pointer">More Info</a>
<? /* *** this is the box that holds more info */ ?>
<div class="more-info <?php tribe_events_event_classes() ?>" style="display:none;">
<? /* *** This is where all the info goes that should be in the hidden box */ ?>
</div>
jQuery(document).ready(function($){
/* when you click the link ... */
$('.more-info-link').click(function(){
var check = "post-";
/* split all the classes into an array ... */
var cls = $(this).attr('class').split(' ');
for (var i = 0; i < cls.length; i++) {
/* if the start of the class in the array is also the start of the "check" variable denoted above ... */
if (cls[i].indexOf(check) > -1) {
/* get the number of the post ... */
var postnum = cls[i].slice(check.length, cls[i].length);
}
}
/* and open the box with the same number in the class as the open link */
$('.more-info.post-'+postnum).toggle('slow');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment