永久链接重写以包含自定义分类术语

时间:2014-08-14 作者:user1729819

我已经使用

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,
    )
);
如果在permalinks页面中仅使用%postname%,则会得到如下URL:

无论什么com/专业/职位名称

我想获取要读取的URL

无论什么com/父术语名称/职位名称

我已经使用“Remove Taxonomy Base Slug”插件删除了discipline部分,但我不知道如何将术语名称包括在内,并使网站其他部分的永久链接不受影响。

1 个回复
SO网友:helgatheviking

我认为您需要在自定义permalink结构中包含discipline变量

/%discipline%/%postname%

结束

相关推荐

显示所有wp_GET_POST_TERMS插件

我使用以下代码来显示我的自定义分类slug。但是,它只显示第一个类别,而不是所有相关类别。我知道这相当简单,与[0]有关,但我不知道如何更改它。$getslugid = wp_get_post_terms( $post->ID, \'opd_taggallery\' ); $getslug = $getslugid [0]->slug; echo $getslug;