【问题标题】:Wordpress - Custom Taxonomy Rewrite URLWordpress - 自定义分类重写 URL
【发布时间】:2020-10-12 16:09:32
【问题描述】:

如何重写自定义分类的 URL(分类已经从主题注册)?

实际网址:domain.com/doctor/dentist/?llocs=peje(llocs=peje 是位置,其中 peje 是位置名称)

如果可能的话,我想要什么: domain.com/peje/doctor/dentist/ 或 domain.com/doctor/dentist/peje

如果我的问题不清楚,请随时问我。

谢谢!

【问题讨论】:

    标签: wordpress url-rewriting taxonomy


    【解决方案1】:

    您可以在注册分类时编写重写规则。试试这个代码 -

      register_taxonomy('type', 'mytest', array(
        'labels' => array(
            'name'          => 'Types'
        ,   'singular_name' => 'Type'
        ,   'search_items'  => 'Search Types'
        ,   'edit_item'     => 'Edit Type'
        ,   'add_new_item'  => 'Add New Type'
        )
    ,   'hierarchical' => true
    ,   'query_var'    => true
    ,   'rewrite'      => array('slug' => 'mytest/type', 'with_front' => false)
    )); // type taxonomy
    

    【讨论】:

    • 分类已经注册,我只需要重写URL。
    • 请检查代码行以重写 slug - 'rewrite' => array('slug' => 'mytest/type', 'with_front' => false)
    • 分类已经像这样注册了(只是它的一个sn-p):pastebin.com/raw/s08RpkZB
    • 您需要更改设置>永久链接并设置“帖子名称”选项并保存。并尝试使用此代码 - $locslug = '/peje/doctor/dentist'; register_taxonomy('listing_location',array('post'), array( 'hierarchical' => true, // false 插入帖子时插入新税 'labels' => $labels, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => $locslug ), ));
    • 是的,但是位置是一个动态值。我希望 ?llocs='location' 成为 /location/doctor/dentist。所以当位置是 peje 时,/peje/doctor/dentist/
    猜你喜欢
    • 2013-02-17
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多