简体   繁体   English

如何获取在Wordpress中按类别过滤的自定义帖子类型的永久链接?

[英]How to get permalink of custom post type that filter by category in Wordpress?

I have a custom post type like 'articles' and use built-in categories like 'rock, pop, jazz, etc' to categorised this articles. 我有一个自定义的帖子类型(例如“文章”),并使用内置的类别(如“摇滚,流行,爵士乐等”)对本文进行了分类。 I have a permalink for 'articles' archive also have permalink to and category archive page like jazz archive page. 我有一个“文章”档案的永久链接,也有与jazz档案页面类似的类别档案页面的永久链接。

But also I want to permalink to articles that filter by specified categories. 但我也想永久链接到按指定类别过滤的文章。 my archive page also handle this conditions but I can't get permalink for this page! 我的存档页面也可以处理这种情况,但是我无法获得此页面的永久链接!

When I type this address to browser 'index.php?post-type=articles&category-name=jazz' this url redirect to /category/jazz/?post-type=articles but I want this is apear in this format /articles/category/jazz 当我在浏览器'index.php?post-type = articles&category-name = jazz'中输入此地址时,此网址重定向到/ category / jazz /?post-type = articles,但我希望它以/ articles / category格式出现/爵士乐

In order to achieve that you first need to register your category with the custom post type and then you can assign categories and have the desired result. 为了实现此目的,您首先需要使用自定义帖子类型注册类别,然后可以分配类别并获得所需的结果。 Use register_taxonomy_for_object_type(); 使用register_taxonomy_for_object_type(); in order to assign category taxonomy to your custom post type. 以便将类别分类法分配给您的自定义帖子类型。 You can get an example here : http://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type 您可以在此处获取示例: http : //codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM