admin管理员组文章数量:1122832
I am writing a theme for Wordpress and I need a tag filter tool for posts, that can filter by multiple tags simultaneously, without a submit button, no checkboxes, no radio’s, and a show all posts button. (See image)
What would be the best way to come at this problem? or can anyone recommend any suitable plugins?
I am writing a theme for Wordpress and I need a tag filter tool for posts, that can filter by multiple tags simultaneously, without a submit button, no checkboxes, no radio’s, and a show all posts button. (See image)
What would be the best way to come at this problem? or can anyone recommend any suitable plugins?
Share Improve this question asked Jun 14, 2020 at 13:32 Theo fordTheo ford 11 bronze badge1 Answer
Reset to default 0I recently wrote a bit of code which filters by one tag at a time only, but it would be pretty easy to modify it to 'toggle' the status of each tag so that you could filter by multiple tags simultaneously. You can see it working here: http://sadcookbook.recipes/sad/ . It uses the following PHP to render the tag links,
Show only:
<?php
$tags = get_tags();
foreach ($tags as $tag) {
$taglinks[] = "<span style=\"cursor: pointer;\" class=\"filter-tag\" id=\"filter-".$tag->slug."\"><b>".$tag->name."</b></span>";
}
echo join($taglinks, " - ");`
Then it uses this jquery together with masonry to display posts depending on which tags have been clicked
jQuery('.filter-tag').click(function() {
showAll();
var $grid = jQuery('#grid-container');
tag = 'tag-' + jQuery(this).attr('id').substring(7)
classSelector = '.' + tag
elementsToRemove = jQuery('#gridcontainer').children().children().not(classSelector).parent()
elementsToRemove.clone().appendTo('#grid-hidden')
$grid.masonry('remove', elementsToRemove)
$grid.masonry('layout')
// Save the elements removed so they can be put back later
elementsToRemove.each(function (index) {
id = jQuery(this).attr('id');
if (!putBack.includes(id))
putBack.push(id)
});
});
本文标签: phpMultiple Tag Filtering
版权声明:本文标题:php - Multiple Tag Filtering 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295748a1929636.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论