douyu0845 2019-08-05 09:16
浏览 46
已采纳

Wordpress:同位素转换的按钮什么都不做

I'm trying to make a dynamic galery of products with categories using Isotope and Woocommerce on wordpress but I'm stuck because the buttons don't do anything when I click on them and the console shows no error and I can't figure out why it doesn't work.

I'm using wordpress 5.2.2 with an ark theme ,bootstrap v4 and jquery version 2.2.4 . I've tried using diferent jquery versions , I've also tried to redo everything in a clean and local wordpress instalation but I had some Animsition errors .

Here is how a build the gallery in php:

function gallery(){

    Print "<div class='button-group filter-button-group'>
            <button data-filter='*' >show all</button>
            <button data-filter='.music-album'>Music</button>
            <button data-filter='.movie-soundtrack'>Movies</button>
            <button data-filter='.game-soundtrack'>Games</button>
            </div>";
    Print"<div class='row'>";

    $articles = new WP_Query(['post_type'=>'product']);

    if($articles->have_posts()) : while ($articles->have_posts()) : $articles->the_post();

        $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
        $single_cat = array_shift( $product_cats );
        $category = $single_cat->slug.' ';

        Print"<a class='grid-item ".$category."' href='".get_the_permalink()."'>";
        Print"<div class='card grid-item".$category."'>";
            Print"<img class='card-img-top'src='".get_field('image')."'alt='' width='200' height='200'>";
            Print"<h1 class='card-body'>"; the_title(); Print"</h1>";
        Print"</div>";
        Print"</a>";


    endwhile;endif; 

    Print"</div>";

}

And here is the javascript :

jQuery.noConflict();

var $grid = jQuery('.grid').isotope({
  // options
  itemSelector: '.grid-item',
  layoutMode: 'fitRows'
});



jQuery('.filter-button-group').on('click', 'button', function() {
  var filterValue = jQuery(this).attr('data-filter');
  console.log(filterValue); // for tests
  $grid.isotope({ filter: filterValue });
});

The buttons should sort the products by category with transitions but when I click it doesn't sort anything at all and the console doesn't return any Error .

  • 写回答

1条回答 默认 最新

  • dsl2014 2019-08-05 10:36
    关注

    As @Manjunath said my "items" were not part of the grid I wanted to sort. So I just had to add "grid" to the class of my galery div .

    Thank You Manjunath !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加