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

获取类别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!

我想知道是否有人知道如何使用jquery在一个类别中的不同标签之间切换可过滤的投资组合 使用wordpress。 p>

这是我目前的代码,用于获取类别中的标记: p>

 &lt; ul&gt; 
&lt;?  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('  &lt; li class =“jquery”&gt;','&lt; / li&gt;&lt; li&gt;','&lt; / li&gt;'); 
} 
 endwhile; 万一;  
 wp_reset_query();  
?&gt; 
&lt; / ul&gt; 
  code>  pre> 
 
 

我无法自定义li元素以显示有用的链接。 p>

如果以前曾问过这个问题,我很抱歉。 我google了,我可以通过自定义帖子类型找到jquery组合过滤,但我不能在我正在构建的网站上使用帖子类型。 p>

任何帮助将不胜感激! p> div>

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.