更改自定义后期类型重写

时间:2012-12-30 10:27:09

标签: wordpress .htaccess mod-rewrite

我有一个自定义主题,为我的投资组合使用自定义帖子类型。 mysite.com/portfolio / 。点击特定投资组合项后,网址将更改为 mysite.com/ 投资组合类型 / name /

将中间的投资组合类型网址更改为另一个值(例如“展示”)的最简单方法是什么?

这里是我的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/ (/ portfolio-type /在网址中添加)

我还想提一下,主题包含 single-portfolio-type.php 文件。

谢谢。

1 个答案:

答案 0 :(得分:1)

也许这会做你想要的:

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]

它将重定向此:

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

对此:

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

如果是相反的方式,我认为是:

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]

它将静默映射此传入的URL ::

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

对此:

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