【问题标题】:Wordpress multiple slugs for a Custom Post Type用于自定义帖子类型的 Wordpress 多个 slug
【发布时间】:2015-08-12 12:49:39
【问题描述】:

可以使用一个 slug 注册自定义帖子类型(例如产品)

register_post_type('products', $args);

如何将多个 slug 添加到同一个自定义帖子类型?

website_address.com/en/products/
website_address.com/fr/produits/
website_address.com/it/prodotti/

【问题讨论】:

  • 不,我只需要一种帖子类型,但有多个 slug。也许 URL 重写?
  • 任何人都可以找到答案,我不需要翻译 slug 我实际上需要多次重写。

标签: wordpress custom-post-type slug


【解决方案1】:

register_post_type() 的重写参数接受一个数组。数组键之一是slug。所以你可以这样:

register_post_type( 
    'products', 
    array (
        'rewrite' => array (
            'slug' => _x( 'products', 'URL slug', 'your_text_domain' )
        )
    )
);

想法来自here

参考:https://codex.wordpress.org/Function_Reference/register_post_type

【讨论】:

    猜你喜欢
    • 2017-01-31
    • 2016-07-01
    • 2017-02-28
    • 2019-09-06
    • 2017-03-30
    • 2021-08-21
    • 2021-10-17
    • 2018-11-23
    • 2017-08-26
    相关资源
    最近更新 更多