WordPress - producing a list of posts filtered by tag and then category(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 - 生成按标签和类别过滤的帖子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WordPress - 生成按标签和类别过滤的帖子列表
基础教程推荐
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01