【问题标题】:WordPress Permalink with custom post type and custom taxonomy具有自定义帖子类型和自定义分类的 WordPress 永久链接
【发布时间】:2012-05-05 00:48:19
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

  • 是的,我搜索过,没有一个解决方案适合我。
  • 不起作用 不是有用的描述。启用调试模式并写下到底出了什么问题。
  • 好吧,它不起作用 - 没有任何改变,没有错误或任何东西。只是不会有什么不同。

标签: wordpress


【解决方案1】:

首先,我会仔细检查创建自定义帖子类型的函数, 在那个函数中应该有一个元素叫做: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 函数是否相同!

即:

 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%/ 并保存,

希望有帮助:)

马蒂

【讨论】:

  • 您是通过functions.php 创建自定义帖子类型还是使用插件为您执行此操作?
  • 我正在使用 functions.php - 这有什么关系?
  • 在使用functions.php时,您可以更好地控制自定义帖子类型的创建方式,您是否可以将用于构建自定义帖子类型的代码和注册分类代码添加到上述问题中更深入的了解..M
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-18
  • 1970-01-01
相关资源
最近更新 更多