Created
June 26, 2021 22:01
-
-
Save tdmrhn/b5badfe59a92e08720f0c1131e8fe703 to your computer and use it in GitHub Desktop.
Blocksy Blog or CPT live jQuery filter CS
This file contains hidden or 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 | |
add_filter( 'blocksy:hero:after', 'blc_jquery_filter', 10); | |
function blc_jquery_filter() { | |
if ( is_home() ) { | |
?> | |
<script> | |
jQuery(document).ready(function($) { | |
$('.ct-filter').on( 'click', function(event){ | |
var $type = $(this).data("filter"); | |
if($type == "all"){ | |
$('.entry-card').fadeOut(0); | |
$('.entry-card').fadeIn(500); | |
} else { | |
$('.entry-card').hide(); | |
// For CPTs just change the category class to your CPTs slug for example: '.projects-' | |
$('.category-' + $type + '.entry-card').fadeIn(500); | |
} | |
}); | |
}); | |
</script> | |
<!-- For CPTs just change the category slug to your CPTs slug for example: 'projects' --> | |
<?php | |
$terms = get_terms( | |
array( | |
'taxonomy' => 'category', | |
'hide_empty' => true, | |
) | |
); | |
if ( ! empty( $terms ) && is_array( $terms ) ) { | |
?> | |
<div class="ct-container" data-vertical-spacing="top"> | |
<a data-filter="all" class="ct-button ct-filter">All</a> | |
<?php | |
foreach ( $terms as $term ) { ?> | |
<a data-filter="<?php echo $term->slug; ?>" class="ct-button ct-filter"> | |
<?php echo $term->name; ?> | |
</a><?php | |
} | |
} | |
?> | |
</div> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment