具有自定义帖子类型和自定义分类法的 WordPress 永久链接 [英] WordPress Permalink with custom post type and custom taxonomy

查看:56
本文介绍了具有自定义帖子类型和自定义分类法的 WordPress 永久链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 product 的自定义帖子类型和一个名为 product_types 的产品自定义分类法,它是分层的,所以我有子类别.

I have a custom post type called product and a custom taxonomy for products called product_types, which is hierarchical, so I have sub-categories in it.

我希望永久链接显示为 http://mysite.com/product_type/sub_category/postname

I want the permalink to show up as http://mysite.com/product_type/sub_category/postname

我尝试了很多插件和我在网上找到的东西,到目前为止没有任何效果.

I tried a lot of plugins and things I found online, nothing worked so far.

谢谢.

推荐答案

首先我会仔细检查创建自定义帖子类型的函数,在该函数中应该有一个元素叫做:rewrite

firstly I would double check the function which is creating your custom post type, within that function there should be an element called: rewrite

即:

register_post_type( 'products',
   'menu_position' => 25, // below pages
   'public' => true,
   'show_ui' => true,
   'rewrite' => array( 'slug' => 'product' ) <-- this is what you need!
);

同样检查 register_taxonomy 函数!

also check the register_taxonomy function for the same!

即:

 register_taxonomy(
  'team',array('product_types'), 
    array(
    'public' => true,
    'show_ui' => true,
    'show_in_nav_menus' => true,
    'query_var' => true,
    'hierarchical' => true, <-- this is needed!
    'rewrite' => true <-- this is what you need!
  )); 

唯一需要检查的是:

您的永久链接结构设置为/%postname%/您可能必须重置为默认值,保存它,然后重新设置为/%postname%/并保存,

your permalink structure is set to /%postname%/ you may have to reset to default, save it, then re-set to /%postname%/ and save,

希望有帮助:)

马蒂

这篇关于具有自定义帖子类型和自定义分类法的 WordPress 永久链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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