dongsuikai8286 2014-03-18 12:13 采纳率: 100%
浏览 44
已采纳

获取类别wordpress中的标签 - 可过滤的投资组合

I'm wondering if anyone knows how I can make a filterable portfolio using jquery to switch between different tags within a category using wordpress.

This is my current code to get the tags in a category:

<ul>
    <?php
        query_posts('category_name=Sport');
        if (have_posts()) : while (have_posts()) : the_post();
            if( get_the_tag_list() ){
                echo $posttags = get_the_tag_list('<li class="jquery">','</li><li>','</li>');
            }
        endwhile; endif; 
        wp_reset_query(); 
    ?>
</ul>

I can't customize the li elements to display usefull link.

I'm sorry if this question has been asked before. I googled around and I could just find jquery portfolio filtering by a custom post type, but I can't use post types on the site I'm building.

Any help will be appreciated!

  • 写回答

1条回答 默认 最新

  • dongzouhe9734 2014-03-18 12:38
    关注

    You can't do it using the code as you have it structured currently. You need to be able to add a filterable attribute to each item in order to establish a proper relationship. Furthermore, we'll need to structure the article it's self so that it has all tags as a class. Then we can easily filter.

     query_posts('category_name=Sport');
     $posttags = get_the_tags();
     $tags_class = implode(' ', $posttags);
     if (have_posts()) : 
         if ($posttags):
             echo '<ul class="jquery">';
             foreach($posttags as $tag) {
                 echo '<li data-filter="'.$tag->name .'"> '.$tag->name.' </li>';
             endforeach;
             echo '</ul>';
         endif;
         while (have_posts()) : the_post();
            //generate the article list for all articles within the sports category
            //the $tags_class variable is a whitespace delimited string of tags for this post
            echo '<article class="filterable '.$tags_class.' ">';
                //the rest of your post, such as the image etc goes in here
            echo '</article>';
    
         endwhile; 
     endif; 
     wp_reset_query(); 
    

    Now for the jQuery.

    $(function () {
        $('ul.jquery > li').click(function () {
            $('.filterable').hide();
            $('.filterable').filter($(this).data('filter')).show();
        });
    });
    

    Here's a jsFiddle illustrating the filter functionality.

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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图