admin管理员组

文章数量:1122832

I've created a custom taxonomy for posts using

register_taxonomy( 
    'discipline', 
    array('post'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
    array(
        'hierarchical' => true,     /* if this is true it acts like categories */             
        'labels' => array(
            'name' => __( 'Disciplines' ), /* name of the custom taxonomy */
            'singular_name' => __( 'Discipline' ), /* single taxonomy name */
            'search_items' =>  __( 'Search Disciplines' ), /* search title for taxomony */
            'all_items' => __( 'All Disciplines' ), /* all title for taxonomies */
            'parent_item' => __( 'Parent Discipline' ), /* parent title for taxonomy */
            'parent_item_colon' => __( 'Parent Discipline:' ), /* parent taxonomy title */
            'edit_item' => __( 'Edit Discipline' ), /* edit custom taxonomy title */
            'update_item' => __( 'Update Discipline' ), /* update title for taxonomy */
            'add_new_item' => __( 'Add New Discipline' ), /* add new title for taxonomy */
            'new_item_name' => __( 'New Discipline Name' ) /* name title for taxonomy */
        ),
        'rewrite' => array(
            'slug' => 'discipline',
            'with_front' => false
        ),
        'show_ui' => true,
        'query_var' => true,
    )
);

If I use just %postname% in the permalinks page, I get URLs like:

whatever/discipline/name-of-post

I want to get the URL to read

whatever/parent-term-name/name-of-post

I've removed the discipline part using the "Remove Taxonomy Base Slug" plugin but can't figure out how to get the term name included AND have permalinks to other parts of the site unaffected.

I've created a custom taxonomy for posts using

register_taxonomy( 
    'discipline', 
    array('post'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
    array(
        'hierarchical' => true,     /* if this is true it acts like categories */             
        'labels' => array(
            'name' => __( 'Disciplines' ), /* name of the custom taxonomy */
            'singular_name' => __( 'Discipline' ), /* single taxonomy name */
            'search_items' =>  __( 'Search Disciplines' ), /* search title for taxomony */
            'all_items' => __( 'All Disciplines' ), /* all title for taxonomies */
            'parent_item' => __( 'Parent Discipline' ), /* parent title for taxonomy */
            'parent_item_colon' => __( 'Parent Discipline:' ), /* parent taxonomy title */
            'edit_item' => __( 'Edit Discipline' ), /* edit custom taxonomy title */
            'update_item' => __( 'Update Discipline' ), /* update title for taxonomy */
            'add_new_item' => __( 'Add New Discipline' ), /* add new title for taxonomy */
            'new_item_name' => __( 'New Discipline Name' ) /* name title for taxonomy */
        ),
        'rewrite' => array(
            'slug' => 'discipline',
            'with_front' => false
        ),
        'show_ui' => true,
        'query_var' => true,
    )
);

If I use just %postname% in the permalinks page, I get URLs like:

whatever.com/discipline/name-of-post

I want to get the URL to read

whatever.com/parent-term-name/name-of-post

I've removed the discipline part using the "Remove Taxonomy Base Slug" plugin but can't figure out how to get the term name included AND have permalinks to other parts of the site unaffected.

Share Improve this question edited Aug 14, 2014 at 22:53 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Aug 14, 2014 at 19:21 user1729819user1729819 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I think you need to include the discipline variable in the custom permalink structure

/%discipline%/%postname%

本文标签: Permalink Rewrite to include Custom Taxonomy Term