更改自定义后类型重写 [英] Change custom post-type rewrite

查看:122
本文介绍了更改自定义后类型重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用自定义文章类型为我的投资组合的,例如自定义主题mysite.com/portfolio / 的。当我点击一个特定的投资组合项目的URL变化的 mysite.com/ 组合型 /姓名/

I have a custom theme that uses custom post types for my portfolio e.g. mysite.com/portfolio/. Once I click on a specific portfolio item the URL changes to mysite.com/portfolio-type/name/

什么是中间修改组合型网址为其他值,例如展示,最简单的方法?

What's the easiest way to change the portfolio-type URL in the middle to another value e.g "showcase"?

我的f​​unctions.php的在这里,自定义文章类型部分:

Here the custom post type part of my functions.php:

    // CUSTOM POST TYPES

    function justins_custom_post_types() {


        // Portfolio

        $labels_portfolio = array(
            'add_new' => 'Add New', 'portfolio-type',
            'add_new_item' => 'Add New Portfolio Post',
            'edit_item' => 'Edit Portfolio Post',
            'menu_name' => 'Portfolio',
            'name' => 'Portfolio', 'post type general name',
            'new_item' => 'New Portfolio Post',
            'not_found' =>  'No portfolio posts found',
            'not_found_in_trash' => 'No portfolio posts found in Trash', 
            'parent_item_colon' => '',
            'singular_name' => 'Portfolio Post', 'post type singular name',
            'search_items' => 'Search Portfolio Posts',
            'view_item' => 'View Portfolio Post',
        );
        $args_portfolio = array(
            'capability_type' => 'post',
            'has_archive' => true, 
            'hierarchical' => true,
            'labels' => $labels_portfolio,
            'menu_position' => 4,
            'public' => true,
            'publicly_queryable' => true,
            'query_var' => true,
            'show_in_menu' => true, 
            'show_ui' => true, 
            'supports' => array( 'comments', 'editor', 'excerpt', 'thumbnail', 'title' ),
            'singular_label' => 'Portfolio',
        );
        register_post_type( 'portfolio-type', $args_portfolio );


    }

    add_action( 'init', 'justins_custom_post_types' );


    // CUSTOM TAXONOMIES

    function justins_custom_taxonomies() {


        // Portfolio Categories 

        $labels = array(
            'add_new_item' => 'Add New Category',
            'all_items' => 'All Categories' ,
            'edit_item' => 'Edit Category' , 
            'name' => 'Portfolio Categories', 'taxonomy general name' ,
            'new_item_name' => 'New Genre Category' ,
            'menu_name' => 'Categories' ,
            'parent_item' => 'Parent Category' ,
            'parent_item_colon' => 'Parent Category:',
            'singular_name' => 'Portfolio Category', 'taxonomy singular name' ,
            'search_items' =>  'Search Categories' ,
            'update_item' => 'Update Category' ,
        );
        register_taxonomy( 'portfolio-category', array( 'portfolio-type' ), array(
            'hierarchical' => true,
            'labels' => $labels,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'portfolio-type/category' ),
            'show_ui' => true,
        ));


        // Portfolio Tags   

        $labels = array(
            'add_new_item' => 'Add New Tag' ,
            'all_items' => 'All Tags' ,
            'edit_item' => 'Edit Tag' , 
            'menu_name' => 'Portfolio Tags' ,
            'name' => 'Portfolio Tags', 'taxonomy general name' ,
            'new_item_name' => 'New Genre Tag' ,
            'parent_item' => 'Parent Tag' ,
            'parent_item_colon' => 'Parent Tag:' ,
            'singular_name' =>  'Portfolio Tag', 'taxonomy singular name' ,
            'search_items' =>   'Search Tags' ,
            'update_item' => 'Update Tag' ,
        );
        register_taxonomy( 'portfolio-tags', array( 'portfolio-type' ), array(
            'hierarchical' => true,
            'labels' => $labels,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'portfolio-type/tag' ),
            'show_ui' => true,
        ));

}

参考网址为主题的投资组合部分: http://html.orange-idea.com/commander/4-columns-portfolio/ (没有问题,这个)

单品: HTTP:/ /html.orange-idea.com/commander/portfolio-type/summer-time/ (/组合型/ URL中添加的)

我也想提一提,主题由单投资组合type.php 文件。

I would also like to mention that the theme consists of a single-portfolio-type.php file.

感谢你。

推荐答案

这也许会做你想要的:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  (.*)/portfolio-type/(.*)
RewriteRule .* http://html.orange-idea.com/%1/showcase/%2  [QSA,R=301,L]

这将重定向这样的:

It will redirect this:

http://html.orange-idea.com/commander/portfolio-type/summer-time/

要这样:

http://html.orange-idea.com/commander/showcase/summer-time/

如果是倒过来的,我觉得是:

If it is the other way around, which I think it is:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  (.*)/showcase/(.*)
RewriteRule .* http://html.orange-idea.com/%1/portfolio-type/%2  [QSA,L]

这将映射默默地这个进入网址::

It will map silently this incoming URL::

http://html.orange-idea.com/commander/showcase/summer-time/

要这样:

http://html.orange-idea.com/commander/portfolio-type/summer-time/

这篇关于更改自定义后类型重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆