Skip to content

Instantly share code, notes, and snippets.

@ohryan
Created September 14, 2011 14:16
Show Gist options
  • Save ohryan/1216670 to your computer and use it in GitHub Desktop.
Save ohryan/1216670 to your computer and use it in GitHub Desktop.
Collapses Wordpress Categories.
/*
* jQuery Wordpress Category Collapse
*
* Automatically collapses categories in your sidebar
*
*/
$(function() {
var thing = $('#subnmenu .page_item').find('ul.children');
var i = 0;
thing.each(
function(){
i++;
var siblings = $(this).siblings();
$(this).attr('id', 'category_'+i)
if (!$(this).parent().hasClass('current_page_ancestor') ) {
$(this).hide();
siblings.after(' <a href="#" class="category_expander active" rel="category_'+i+'" style="float:right">+</a>');
} else {
siblings.after(' <a href="#" class="category_expander" rel="category_'+i+'" style="float:right">-</a>');
}
}
);
$('.category_expander').click(
function(evt) {
evt.preventDefault();
var id = $(this).attr('rel')
$(this).toggleClass('active');
$('#'+id).toggle();
$(this).text(($(this).hasClass('active') ? '+': '-'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment