从 WordPress 中的 URL 中删除分类库

发布于 2024-12-05 09:01:52 字数 642 浏览 2 评论 0原文

我在从 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)
);

我目前看到的网址如下: http://mysite.com/project-category/project1我希望它是这样的:http://mysite.com/project1

我尝试将 slug 重写为“”而不是“项目类别”,但这弄乱了我的所有其他页面,重定向到 404 页面。

I have a little problem with removing the taxonomy base from the URL in Wordpress. I tried different approaches but none worked.

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

I currently see the URL like this : http://mysite.com/project-category/project1 and i want it to be like this: http://mysite.com/project1.

I tried to rewrite the slug to '' instead 'project-category' but that messed with all my othr pages, redirecting to a 404 page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧伤慢歌 2024-12-12 09:01:52

这是我如何设法将我的网址重写为特定网址的方法。

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 自定义帖子类型
  2. 坚如磐石的 WordPress 3.0帖子类型
  3. 自定义帖子类型工具&建议

Heres how I've manage to get my url to rewirte to a spcific 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
));

Also check out some tutorials and sometimes you can grab bits& pieces from theme.

  1. Wordpress custom post types
  2. Rock solid wordpress 3.0 post types
  3. Custom post type tools & advice
一枫情书 2024-12-12 09:01:52

尝试这个

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

Try this

Just drop it into wp-content/plugins and activate. It is in the process of being added to the WP repository.

毁虫ゝ 2024-12-12 09:01:52

use this plugin https://github.com/alexvornoffice/remove-taxonomy-base-slug,
what this does?
It removes base slug from all taxonomies, and check if the slug is the same as post type slug, and rewrites the rules in the such way so the taxonomy slug will have a better priority over post type slug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文