Created
October 20, 2017 18:58
-
-
Save nikola0203/79b703f6f0b218af0301f291147b0d94 to your computer and use it in GitHub Desktop.
Dynamic category filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $category = get_the_category(); ?> | |
<div class="col-md-6 filter <?php echo esc_attr( $category[0]->slug ); ?>"> | |
// Content | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div <?php post_class( 'filter col-sm-6 col-md-4' ); ?>> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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