Skip to content

Instantly share code, notes, and snippets.

@taciara
Last active May 6, 2019 14:37
Show Gist options
  • Select an option

  • Save taciara/b5e989dd0ccf5003dcdaab6bc4342e37 to your computer and use it in GitHub Desktop.

Select an option

Save taciara/b5e989dd0ccf5003dcdaab6bc4342e37 to your computer and use it in GitHub Desktop.
Usar o filterizr com taxonomia. Este código você pode usar como uma galeria de fotos com filtragem / categoria.
/*
javascript
tem que incluir esse arquivo js: https://cdn.rawgit.com/giotiskl/Filterizr/1.3.4/dist/jquery.filterizr.min.js
*/
window.jQuery(function ($) {
var $filterizd = $('.projects-gallery .items').filterizr({
filter: 'all',
layout: 'sameSize',
});
$('.projects-gallery .filters button').on('click', function () {
$('.projects-gallery .filters button').removeClass('active');
$(this).addClass('active');
});
});
<?php
// adiciona no functions php
// e usa shortcode [show_projects] para mostrar na página
add_shortcode( 'show_projects', function () {
$taxonomy = 'post_tag';
$post_type = 'post';
$posts = get_posts( [
'post_type' => $post_type
] );
$terms = get_terms( $taxonomy );
ob_start();
?>
<div class="projects-gallery">
<div class="filters">
<button data-filter="all" class="active">Todos</button>
<?php foreach( $terms as $term ) : ?>
<button data-filter="<?php echo $term->term_id; ?>"><?php echo $term->name; ?></button>
<?php endforeach; ?>
</div>
<div class="items">
<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
<?php
$terms = wp_get_post_terms( $post->ID, $taxonomy );
$term_ids = [];
foreach( $terms as $term ) {
$term_ids[] = $term->term_id;
}
?>
<div class="filtr-item project" data-category="<?php echo implode(',', $term_ids); ?>">
<!-- conteudo de cada projeto aqui -->
<h2><?php echo $post->post_title; ?></h2>
</div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</div>
<?php
return ob_get_clean();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment