如何在 WordPress 中使用永久链接列出自定义分类中的所有项目
不知道如何表达这个。我在 WordPress 中设置了一个名为 Products
的自定义帖子类型。我还有两个与 Products
链接的分类法,称为 Brands
和 Categories
。创建产品时,您可以设置产品所属的品牌
和类别
。当使用类型作为永久链接来列出类型中的所有内容时,它工作得很好
http://sitename.com/products
,但我似乎无法让分类法以相同的方式工作,即。列出分类法中的所有项目(我想是档案):
http://sitename.com/brands
http://sitename.com/categories
这可能吗?如果可以,我可能做错了什么?我会尝试在 functions.php
中设置一些重写规则,但如果您想在分类中列出项目,我不知道查询字符串是什么样子,也不知道这是否可能。如果有帮助,我正在使用插件 更多类型 和 Ultimate Taxonomy Manager 创建类型和分类法。
Not sure how to word this. I've set up a custom post type in WordPress called Products
. I also have two taxonomies linked to Products
called Brands
and Categories
. When you create a product you can set to which Brand
and Category
the product belongs. It works perfectly when using the type as permalink to list everything within a type
http://sitename.com/products
but I can't seem to get the taxonomies working in the same way, ie. list all the items within a taxonomy (like an archive, I suppose):
http://sitename.com/brands
http://sitename.com/categories
Is this possible, and if so, what could I possibly be doing wrong? I would try and set up some rewrite rules in functions.php
, but I don't know what the query string looks like if you want to list items in a taxonomy, and if this is even possible. If it helps, I'm using the plugins More Types and Ultimate Taxonomy Manager to create the types and taxonomies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
目前还没有真正的方法可以做到这一点。 WP 正在朝这个方向发展,并且在 3.1 中为自定义帖子类型设置了顶层,但仍然没有分类法。这很笨拙,但我添加了一个名为 page-products.php 的页面,然后将我的列表放在那里。
There's not really a way to do this yet. WP is moving this direction and with 3.1 is setting up a top-level for custom post types, but still nothing for taxonomies. It's klunky but I added a page called page-products.php and then put my list in there.
仅供参考,该插件的正确链接(我是作者)现在是 http://www.get10up.com/plugins/simple-custom-post-type-archives-wordpress/
它确实应该使用 3.1 中的内置存档功能来完成 - 该插件是为3.0。
FYI the correct link for that plugin (I'm the author) is now http://www.get10up.com/plugins/simple-custom-post-type-archives-wordpress/
And it should really be done using the built in archives feature in 3.1 - the plugin was built for 3.0.
有Trac 票证,但不清楚最明显的事情是什么在此页面上显示:
WordPress Stack Exchange 上的类似问题 询问选项 2,您的问题可以用两种方式解释:当您说分类中的所有项目时,您是指该分类的所有术语,还是所有与该分类的术语相关的帖子?
目前,您可以使用查询变量控制的主查询(循环)将始终返回posts,而不是terms。正如票证中所述,选项 2 需要循环返回此查询的术语,这可能会导致没有模板的主题出现兼容性问题。在此实施之前,大卫的回答可能是正确的选择。
There is a Trac ticket for this, but it's not clear what would the most obvious thing to show on this page:
A similar question on the WordPress Stack Exchange asked for option 2, and your question can be interpreted both ways: when you say all items within a taxonomy, do you mean all terms of this taxonomy, or all posts that are linked to a term of this taxonomy?
Currently the main query (the Loop) that you can control with the query vars will always return posts, not terms. As said in the ticket, option 2 would require the Loop to return terms for this query, possibly causing compatibility issues for themes that don't have a template for it. Until that is implemented, David's answer is probably the way to go.
感谢您的回答!我找到了一个完全符合我想要的插件 - 在手动编码所有内容之后:/
http://www.thinkoomph.com/plugins-modules/wordpress-custom-post-type-archives/
Thanks for the answers! I've found a plugin that does exactly what I wanted - after manually coding everything :/
http://www.thinkoomph.com/plugins-modules/wordpress-custom-post-type-archives/
使用 WP htaccess 控制插件
http://wordpress.org/extend/plugins/wp-htaccess-control/
在选项中,您可以删除所选分类法的基础。
为我工作,希望它也为你工作:)
Use the WP htaccess Control Plugin
http://wordpress.org/extend/plugins/wp-htaccess-control/
In the options , you can remove the base of taxonomies you select.
Worked for me, hope It works for you as well :)