ms_photo_author
分类学作者ms_photo_color
对于分类颜色ms_photo_cat
对于分类主题,我想设置slug/photographies/
自定义帖子类型的basename 对于这3种分类法蛞蝓。这些URL实际上可以工作:
我创建了4个页面,并将模板文件创建为索引页面。
但是,我想将这些URL转换为:
网站/摄影/主题/网站/摄影/couleurs/网站/摄影/membres/我为最后3页设置了父页摄影,但这些页面会导致404页。保持一个好的SEO的层次结构是至关重要的。
我知道关于这个问题有很多话题,但我感到困惑和迷茫。我不想安装插件来解决我的问题(安全问题)。
以下是用于注册我的CPT和分类法的代码:
function ms_register_post_type() {
$gallery_labels = array(
\'name\' => _x( \'Photographies des membres\', \'Post type general name\', \'ms-photo-gallery\' ),
\'singular_name\' => _x( \'Galerie\', \'Post type singular name\', \'ms-photo-gallery\' ),
\'menu_name\' => _x( \'Galeries\', \'Admin Menu text\', \'ms-photo-gallery\' ),
\'name_admin_bar\' => _x( \'Galeries\', \'Add New on Toolbar\', \'ms-photo-gallery\' ),
);
$gallery_args = array(
\'labels\' => $gallery_labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'photographies\',\'with_front\' => false ),
\'capability_type\' => \'page\',
\'has_archive\' => true,
\'hierarchical\' => true,
\'menu_position\' => 5,
\'supports\' => array(\'title\', \'thumbnail\', \'post-formats\' ),
\'menu_icon\' => \'dashicons-images-alt\',
);
register_post_type( \'ms_photo_portfolio\', $gallery_args );
}
add_action( \'init\', \'ms_register_post_type\');
/**
* Register Portfolio taxonomies
*
*
*/
function ms_create_taxonomies() {
//TAXONOMIE PERSONNALISEE -> CATEGORIES
$category_labels = array(
\'name\' => _x( \'Thèmes\', \'taxonomy general name\', \'ms-photo-gallery\' ),
\'singular_name\' => _x( \'Thème\', \'taxonomy singular name\', \'ms-photo-gallery\' ),
\'search_items\' => __( \'Rechercher des catégories\', \'ms-photo-gallery\' ),
\'all_items\' => __( \'Toutes les catégories\', \'ms-photo-gallery\' ),
\'parent_item\' => __( \'Catégorie parente\', \'ms-photo-gallery\' ),
\'parent_item_colon\' => __( \'Catégorie parente : \', \'ms-photo-gallery\' ),
\'edit_item\' => __( \'Éditer la catégorie\', \'ms-photo-gallery\' ),
\'update_item\' => __( \'Mettre à jour la catégorie\', \'ms-photo-gallery\' ),
\'add_new_item\' => __( \'Ajouter une catégorie\', \'ms-photo-gallery\' ),
\'new_item_name\' => __( \'Nom de la catégorie\', \'ms-photo-gallery\' ),
\'menu_name\' => __( \'Thèmes\', \'ms-photo-gallery\' ),
);
$category_args = array(
\'hierarchical\' => true,
\'labels\' => $category_labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'themes\',\'with_front\' => false ),
);
register_taxonomy(\'ms_photo_cat\', array(\'ms_photo_portfolio\'), $category_args);
// TAXONOMIE PERSONNALISEE -> PHOTOGRAPHES
$photographer_labels = array(
\'name\' => _x( \'Photographes\', \'taxonomy general name\', \'ms-photo-gallery\' ),
\'singular_name\' => _x( \'Photographe\', \'taxonomy singular name\', \'ms-photo-gallery\' ),
\'search_items\' => __( \'Rechercher des photographes\', \'ms-photo-gallery\' ),
\'all_items\' => __( \'Tous les photographes\', \'ms-photo-gallery\' ),
\'edit_item\' => __( \'Editer le profil\', \'ms-photo-gallery\' ),
\'update_item\' => __( \'Mettre à jour le profil\', \'ms-photo-gallery\' ),
\'add_new_item\' => __( \'Ajouter un profil\', \'ms-photo-gallery\' ),
\'new_item_name\' => __( \'Nom du photographe\', \'ms-photo-gallery\' ),
\'menu_name\' => __( \'Photographes\', \'ms-photo-gallery\' ),
);
$photographer_args = array(
\'hierarchical\' => true,
\'labels\' => $photographer_labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'membres\',\'with_front\' => false ),
);
register_taxonomy(\'ms_photo_author\', array(\'ms_photo_portfolio\'), $photographer_args);
// Color taxonomy (non-hierarchical)
$labels = array(
\'name\' => \'Couleurs\',
\'singular_name\' => \'Couleur\',
\'search_items\' => \'Rechercher des couleurs\',
\'popular_items\' => \'Couleurs populaires\',
\'all_items\' => \'Toutes les couleurs\',
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => \'Editer la couleur\',
\'update_item\' => \'Mettre à jour la couleur \',
\'add_new_item\' => \'Ajouter une couleur\',
\'new_item_name\' => \'Nom de la couleur\',
\'separate_items_with_commas\' => \'Séparer les couleurs avec des virgules\',
\'add_or_remove_items\' => \'Ajouter ou supprimer des couleurs\',
\'choose_from_most_used\' => \'Choisir parmis les couleurs les plus utilisées\',
\'not_found\' => \'Pas de couleur trouvée.\',
\'menu_name\' => \'Couleurs\',
);
$args = array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'couleurs\',\'with_front\' => false ),
);
// associer cette taxonomie au portfolio et aux médias.
register_taxonomy( \'ms_photo_color\', array( \'ms_photo_portfolio\' ), $args );
}
add_action(\'init\', \'ms_create_taxonomies\');
/**
* Rewrite Flush
*
*
*/
function ms_rewrite_flush() {
// First, we "add" the custom post type via the above written function.
// Note: "add" is written with quotes, as CPTs don\'t get added to the DB,
// They are only referenced in the post_type column with a post entry,
// when you add a post of this CPT.
ms_register_post_type();
// ATTENTION: This is *only* done during plugin activation hook in this example!
// You should *NEVER EVER* do this on every page load!!
flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'ms_rewrite_flush\' );
提前感谢您的帮助,马拉尔。