Skip to content

Instantly share code, notes, and snippets.

@nikola0203
Created October 20, 2017 18:58
Show Gist options
  • Save nikola0203/79b703f6f0b218af0301f291147b0d94 to your computer and use it in GitHub Desktop.
Save nikola0203/79b703f6f0b218af0301f291147b0d94 to your computer and use it in GitHub Desktop.
Dynamic category filter
<?php $category = get_the_category(); ?>
<div class="col-md-6 filter <?php echo esc_attr( $category[0]->slug ); ?>">
// Content
</div>
<div <?php post_class( 'filter col-sm-6 col-md-4' ); ?>>
</div>
$.fn.categoryFilter = function(selector){
this.click( function() {
var categoryValue = $(this).attr('data-filter');
$(this).parent().addClass('active').siblings().removeClass('active');
if(categoryValue=="all") {
$('.filter').show(1000);
} else {
$(".filter").not('.'+categoryValue).hide('3000');
$('.filter').filter('.'+categoryValue).show('3000');
}
});
}
$('.category-filter .category-button').categoryFilter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment