WordPress-产生按标签和类别过滤的帖子列表 [英] WordPress - producing a list of posts filtered by tag and then category

查看:110
本文介绍了WordPress-产生按标签和类别过滤的帖子列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个在页面上有六个列表的WordPress网站,每个列表显示来自不同类别的帖子.很简单.

I'm trying to make a WordPress site that has six lists on a page, each list showing posts from a different category. Simple.

但是,如果用户选择一个标签,将其带到该标签存档页面,我希望他们仍然看到六列表模板,但是每个类别中的所有帖子也会被该标签过滤.因此,帖子列表首先按标签过滤,然后按类别过滤.

But then, if a user selects a tag, taking them to that tag archive page, I want them to still see the six-list template, but all the posts within each category are also filtered by the tag. So lists of posts are filtered first by tag, and then by category.

据我所知,无法使用query_posts或其他任何方式来执行此操作,它需要更高级地使用数据库,但是我不知道如何执行此操作!我认为这里也有类似的问题,但是因为我对PHP知之甚少,而对MySQL却不了解,所以我无法理解答案!

As far as I can tell, there is no way of doing this using query_posts or anything, it needs more advanced use of the database, but I have no idea how to do this! I think that there's a similar question on here, but because I know very little PHP and no MySQL, I can't make sense of the answers!

推荐答案

对,我终于找到了一个相对简单的解决方案.

Right, I have finally found a relatively simple solution to this.

WordPress中有一个错误,无法同时查询类别和标签,因此query_posts('cat=2&tag=bread');不起作用,但是一种解决方法是query_posts('cat=2&tag=bread+tag=bread');神奇地起作用.

There's a bug in WordPress preventing a query of both category and tags working, so query_posts('cat=2&tag=bread'); wouldn't work, but a way around this is query_posts('cat=2&tag=bread+tag=bread'); which magically works.

在tag.php模板中,我希望它从该存档中拾取标签,所以我必须这样做:

In a tag.php template, I wanted it to pick up the tag from that archive, so I had to do this:

<?php query_posts('cat=12&tag='.$_GET['tag'].'+'.$_GET['tag']); ?>

效果很好.

这篇关于WordPress-产生按标签和类别过滤的帖子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆