【问题标题】:Custom taxonomy slug issues自定义分类蛞蝓问题
【发布时间】:2017-08-04 17:12:08
【问题描述】:

我的自定义分类有一个奇怪的问题。我想重写蛞蝓。但是当我尝试使用 slug 显示分类时,我只得到分类名称作为 slug 而不是 rewrite slug。

所以我的分类称为models-cat,我想要的是。当我显示分类时,我不想在分类名称之前重写 slug,例如 /rewrite/taxonomy

有人知道吗?

【问题讨论】:

  • 如果您使用的是 apache 网络服务器,请编辑 wordpress 根目录中的 .htaccess 文件以添加 URL 重写规则。看到这个other question
  • @mch 感谢您的回答,但我不喜欢以硬编码的方式进行操作..

标签: php wordpress taxonomy


【解决方案1】:

可以在 register_taxonomy 函数中定义分类 slug 的重写。

$taxonomy_name = 'models-cat';
$taxonomy_post_type = 'post';

register_taxonomy($taxonomy_name, $taxonomy_post_type, array(
    'labels' => array(
        'name' => 'Cats',
        'singular_name' => 'Cat',
        'search_items' => 'Search Cats',
        'edit_item' => 'Edit Cat',
        'add_new_item' => 'Add New Cat',
    ),
    'hierarchical' => true,
    'query_var' => true,
    'rewrite' => array('slug' => 'model/cat', 'with_front' => false)
));

来源:The Right Way to do WordPress Custom Taxonomy Rewrites

【讨论】:

    猜你喜欢
    • 2013-03-24
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 2015-11-13
    • 2016-07-22
    • 2016-07-27
    • 2011-10-18
    • 2022-11-09
    相关资源
    最近更新 更多