【问题标题】:Remove taxonomy-base from URL in WordPress从 WordPress 中的 URL 中删除分类库
【发布时间】:2011-11-20 22:02:15
【问题描述】:

我在从 Wordpress 的 URL 中删除分类库时遇到了一点问题。我尝试了不同的方法,但都没有奏效。

register_taxonomy('project_category','projects',array(
  'labels' => $labels,
  'show_ui' => true,
  'rewrite' => array(
      'slug' => 'project-category',
      'with_front' => false,
      'hierarchical' => true),
  'hierarchical' => true)
);

我目前看到这样的 URL:http://mysite.com/project-category/project1,我希望它是这样的:http://mysite.com/project1

我试图将 slug 重写为 '' 而不是 'project-category' 但这与我所有的其他页面都混淆了,重定向到 404 页面。

【问题讨论】:

  • 真的吗?没有人知道如何做到这一点?...

标签: wordpress url url-rewriting taxonomy


【解决方案1】:

使用这个插件https://github.com/alexvornoffice/remove-taxonomy-base-slug, 这是做什么的? 它从所有分类中删除基本 slug,并检查 slug 是否与 post 类型 slug 相同,并以这种方式重写规则,以便分类 slug 比 post 类型 slug 具有更好的优先级。

【讨论】:

    【解决方案2】:

    试试this

    只需将其放入wp-content/plugins 并激活即可。它正在被添加到 WP 存储库中。

    【讨论】:

    • 您能解释一下“这个”是什么,以及为什么它有助于解决所提出的问题吗?另外,请附上它的用法示例?
    【解决方案3】:

    这就是我如何设法让我的 url 重定向到一个特定的 url。

    add_action('init', 'portfolio_register');  
    
    function portfolio_register() {  
    $args = array(  
        'label' => __('Portfolio'),  
        'singular_label' => __('Project'),  
        'public' => true,  
        'show_ui' => true,  
        'capability_type' => 'post',  
        'hierarchical' => false,  
        'rewrite' => true,  
        'supports' => array('title', 'editor', 'thumbnail')  
       );  
    
    register_post_type( 'portfolio' , $args );  
    }  
    
    register_taxonomy(
       "project-type", 
       array("portfolio"), 
       array("hierarchical" => true, 
       "label" => "Project Types", 
       "singular_label" => "Project Type", 
       "rewrite" => true
    ));
    

    还可以查看一些教程,有时您可以从主题中获取点点滴滴。

    1. Wordpress custom post types
    2. Rock solid wordpress 3.0 post types
    3. Custom post type tools & advice

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 2017-07-04
      • 1970-01-01
      • 2016-09-02
      • 2015-10-31
      • 2014-08-17
      • 2020-03-16
      • 1970-01-01
      • 2018-03-20
      相关资源
      最近更新 更多