我试图弄清楚以下几点:
我有一个CPT叫做;播客“;其中有一个slug as/podcasts,我有一个页面叫做;播客“;其中有一个slug as/podcasts/我希望我的单个podcast帖子有一个永久链接/podcasts/%podcast\\u category%/post\\u name
当我这样做时,我无法编辑播客页面,因为wordpress会显示归档页面。如何修改代码,使归档页面具有不同的slug,但仍保留单个播客的/podcasts/%podcast\\u category%/post\\u名称,并且/podcasts/可以用作页面。
//register podcast posts
function custom_post_podcasts_register(){
$labels = array(
\'name\' => _x(\'Podcast\', \'post type general name\'),
\'singular_name\' => _x(\'Podcast\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'podcast\'),
\'add_new_item\' => __(\'Add New Podcast\'),
\'edit_item\' => __(\'Edit Podcast\'),
\'new_item\' => __(\'New Integration\'),
\'view_item\' => __(\'View Podcast\'),
\'search_items\' => __(\'Search Podcast\'),
\'not_found\' => __(\'Nothing found\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'show_in_rest\' => true,
\'rewrite\' => array(\'slug\' => \'podcasts\',\'with_front\' => false),
\'has_archive\' => \'podcast-all\',
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'excerpt\',\'podcast_category\', \'podcast_tags\'),
\'taxonomies\' => array( \'podcast_category\', \'podcast_tags\' ),
\'menu_icon\' => \'dashicons-format-quote\',
\'has_archive\' => true
);
register_post_type(\'podcast\' , $args);
}
add_action(\'init\', \'custom_post_podcasts_register\');
add_filter(\'manage_edit-podcast_columns\', \'admin_remove_columns\');
//create a custom taxonomy name it "type" for your posts
function podcast_custom_taxonomy() {
$labels = array(
\'name\' => _x( \'Podcast Category\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'podcast_category\', \'taxonomy singular name\' ),
\'edit_item\' => __( \'Edit Podcast Category\' ),
\'update_item\' => __( \'Update Podcast Category\' ),
\'add_new_item\' => __( \'Add New Podcast Category\' ),
\'new_item_name\' => __( \'New Podcast Category Name\' ),
\'menu_name\' => __( \'Podcast Category\' ),
);
register_taxonomy(\'podcast_category\',array(\'podcast\'), array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
\'show_in_rest\' => true,
\'rewrite\' => array( \'slug\' => \'podcast_category\' ),
));
}
// Let us create Taxonomy for Custom Post Type
add_action( \'init\', \'podcast_custom_taxonomy\', 0 );
// Register Custom Taxonomy
function podcast_tags_taxononmy() {
$labels = array(
\'name\' => \'Podcast Tag\',
\'singular_name\' => \'Podcast Tag\',
\'menu_name\' => \'Podcast Tags\',
\'all_items\' => \'All Podcast Tags\',
\'parent_item\' => \'Parent Podcast Tag\',
\'parent_item_colon\' => \'Parent Podcast Tag:\',
\'new_item_name\' => \'New Podcast Tag\',
\'add_new_item\' => \'Add New Podcast Tag\',
\'edit_item\' => \'Edit Podcast Tag\',
\'update_item\' => \'Update Podcast Tag\',
\'separate_items_with_commas\' => \'Separate Podcast Tags with commas\',
\'search_items\' => \'Search Podcast Tags\',
\'add_or_remove_items\' => \'Add or remove Podcast Tags\',
\'choose_from_most_used\' => \'Choose from the most used Podcast Tags\',
\'not_found\' => \'Not Found\',
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
\'show_in_rest\' => true,
);
register_taxonomy( \'podcast-tags\', array( \'podcast\' ), $args );
}
// Hook into the \'init\' action
add_action( \'init\', \'podcast_tags_taxononmy\', 0 );