我有一个自定义的帖子类型来列出国家/地区,但我不确定如何使用这种永久链接结构创建它们:
国家档案馆:/map
乡村单曲:/map/country/england
我如何才能做到这一点?这是我的国家邮政编码:
function countries() {
$labels = array(
\'name\' => _x( \'countries\', \'Post Type General Name\', \'countries\' ),
\'singular_name\' => _x( \'country\', \'Post Type Singular Name\', \'countries\' ),
\'menu_name\' => __( \'Countries\', \'countries\' ),
\'name_admin_bar\' => __( \'Country\', \'countries\' ),
\'parent_item_colon\' => __( \'Parent Country\', \'countries\' ),
\'all_items\' => __( \'All Countries\', \'countries\' ),
\'add_new_item\' => __( \'Add New Country\', \'countries\' ),
\'add_new\' => __( \'Add New Country\', \'countries\' ),
\'new_item\' => __( \'New Country\', \'countries\' ),
\'edit_item\' => __( \'Edit Country\', \'countries\' ),
\'update_item\' => __( \'Update Country\', \'countries\' ),
\'view_item\' => __( \'View Country\', \'countries\' ),
\'search_items\' => __( \'Search Countries\', \'countries\' ),
\'not_found\' => __( \'Country Not found\', \'countries\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'countries\' ),
\'items_list\' => __( \'Country list\', \'countries\' ),
\'items_list_navigation\' => __( \'Countries List Navigation\', \'countries\' ),
\'filter_items_list\' => __( \'Filter Country List\', \'countries\' ),
);
$rewrite = array(
\'slug\' => \'country\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
$args = array(
\'label\' => __( \'country\', \'countries\' ),
\'description\' => __( \'Country Information\', \'countries\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\', \'trackbacks\', \'revisions\', \'custom-fields\', \'page-attributes\', ),
\'taxonomies\' => array( \'category\', \'post_tag\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'capability_type\' => \'page\',
);
register_post_type( \'countries\', $args );
}
add_action( \'init\', \'countries\', 0 );
我也在尝试以下分类法,但即使在我更新permalink设置页面时,它也是404:
register_taxonomy(
\'region\',
\'country\',
[
\'label\' => __( \'Region\' ),
\'rewrite\' => array( \'slug\' => \'map/region\' ),
\'hierarchical\' => true,
]
);