繁体   English   中英

组合过滤器同位素Wordpress

[英]Combination filters Isotope Wordpress

我在Wordpress网站上使用Isotope来过滤我的自定义帖子。 我有一部CPT电影( production )和多种分类法: type (动画/恐怖...), years (2012年/ 2013年)等等。

目前,我可以按年份排序,并且在模板页面中,此代码可以正常运行:

<div class="row">
    <ul id="filters">
        <li>Selectionner</li>
    <li><a href="#" data-filter="*" class="selected">Toutes les années</a></li>
        <?php 
            $terms = get_terms("annee"); // get all categories, but you can use any taxonomy
            $count = count($terms); //How many are they?
            if ( $count > 0 ){  //If there are more than 0 terms
                foreach ( $terms as $term ) {  //for each term:
                    echo "<li><a href='#' data-filter='.".$term->slug."'>" . $term->name . "</a></li>\n";
                    //create a list item with the current term slug for sorting, and name for label
                }
            } 
        ?>
</ul>

在列表之后,显示所有帖子并按年份排序的循环:

<?php 
$the_query = new WP_Query( array(
     'posts_per_page' => 16,
     'post_type' => array( 'production' )
)); //Check the WP_Query docs to see how you can limit which posts to display ?>
<?php if ( $the_query->have_posts() ) : ?>
    <div id="isotope-list">
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); 
            $termsArray = get_the_terms( $post->ID, "annee" );  //Get the terms for this particular item
            $termsString = ""; //initialize the string that will contain the terms
                foreach ( $termsArray as $term ) { // for each term 
                    $termsString .= $term->slug.' '; //create a string that has all the slugs 
                }
            ?> 
            <div class="<?php echo $termsString; ?> item three columns gallery grid"> <?php // 'item' is used as an identifier (see Setp 5, line 6) ?>

                   <figure class="effect-ming">
                         <?php the_post_thumbnail('miniature-film');  ?>
                        <figcaption>
                            <h2><?php the_title('') ?></h2>
                            <p class="serif"><?php the_field('realisation'); ?><p>
                        </figcaption>       

                    </figure>
            </div> <!-- end item -->
        <?php endwhile;  ?>
<?php else : ?>
<p>Aucun résultat ne correspond à votre recherche </p>
<a href="<?php bloginfo('url'); ?>/catalogue">Retour au catalogue</a>
</div> <!-- end isotope-list -->
<?php endif; ?>                 
</div>

和以下javascript:

jQuery(function ($) {

    var $container = $('#isotope-list'); //The ID for the list with all the blog posts
    $container.isotope({ //Isotope options, 'item' matches the class in the PHP
        itemSelector : '.item', 
        layoutMode : 'masonry'
    });

    //Add the class selected to the item that is clicked, and remove from the others
    var $optionSets = $('#filters '),
    $optionLinks = $optionSets.find('a');

    $optionLinks.click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
            return false;
        }
        var $optionSet = $this.parents('#filters');
        $optionSets.find('.selected').removeClass('selected');
        $this.addClass('selected');

        //When an item is clicked, sort the items.
        var selector = $(this).attr('data-filter');
        $container.isotope({ filter: selector });

        return false;
    });

});

(function( $ ) {
    $( function() {

        var $container = $('.isotope').isotope({
            itemSelector: '.element-item',
            layoutMode: 'fitRows'
        });

        $('#filters').on( 'click', 'button', function() {
            var filterValue = $( this ).attr('data-filter');
            $container.isotope({ filter: filterValue });
        });

    });
})(jQuery);

但是我想制作多个过滤器(如年份)并同时使用它们,但是我不知道该怎么做。

我试图复制我years使用的代码,并按"type"更改该段代码,但是没有用。

这是一个示例,向您显示我想做什么: http : //codepen.io/desandro/pen/GFbAs

它是由同位素制成的,而不是由Wordpress函数制成的,因此我不知道如何更改它。

首先,将新的自定义数据参数添加到您的链接中,例如data-filter-two=""

然后添加一个额外的jQuery click函数来处理该过滤-

$('#filters').on( 'click', 'button', function() {
    var filterValue = $( this ).attr('data-filter-two');
    $container.isotope({ filter: filterValue });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM