Est-il possible d'ajouter un menu de type de message personnalisé comme autre sous-menu de type de message personnalisé
2 réponses
- votes
-
- 2013-08-18
Oui. Lorsque vousenregistrez votretype demessage,vous devez définir
show_in_menu
sur lapage sur laquelle vous souhaitez qu'il s'affiche.Ajout d'untype demessagepersonnaliséen tant que sous-menu demessages
Ici,nous définissons letype depublication "films" àinclure dans le sous-menu sous Messages.
register_post_type( 'movies', array( 'labels' => array( 'name' => __( 'Movies' ), 'singular_name' => __( 'Movie' ) ), 'public' => true, 'has_archive' => true, 'show_in_menu' => 'edit.php' ) );
Si vous avez unetaxonomieenregistréepour letype depublicationpersonnalisé,elle devra également être ajoutée à lapage.
Dans
add_submenu_page()
,lepremier argumentest lapage à laquelle l'attribueret le le dernierest le slug demenu.add_action('admin_menu', 'my_admin_menu'); function my_admin_menu() { add_submenu_page('edit.php', 'Genre', 'Genre', 'manage_options', 'edit-tags.php?taxonomy=genre'); }
Ajout d'untype depublicationpersonnaliséen tant que sous-menu d'un autretype depublicationpersonnalisé
Pour ajouter lespages à un autretype depublicationpersonnalisé,incluez leparamètre de chaîne de requête dutype depublication avec lesnoms depage.
Pour ajouter lesfilms CPTet sataxonomie Genre sous letype depublication Divertissement,ajustez le code comme ceci.
edit.php
devientedit.php?post_type=entertainment
edit-tags.php
devientedit-tags.php?taxonomy=genre&post_type=entertainment
register_post_type( 'movies', array( 'labels' => array( 'name' => __( 'Movies' ), 'singular_name' => __( 'Movie' ) ), 'public' => true, 'has_archive' => true, 'show_in_menu' => 'edit.php?post_type=entertainment' ) ); add_action('admin_menu', 'my_admin_menu'); function my_admin_menu() { add_submenu_page('edit.php?post_type=entertainment', 'Genre', 'Genre', 'manage_options', 'edit-tags.php?taxonomy=genre&post_type=entertainment'); }
Yes. When you register your post type you need to set
show_in_menu
to the page you would like it displayed on.Adding a custom post type as a sub-menu of Posts
Here we set the "movies" post type to be included in the sub-menu under Posts.
register_post_type( 'movies', array( 'labels' => array( 'name' => __( 'Movies' ), 'singular_name' => __( 'Movie' ) ), 'public' => true, 'has_archive' => true, 'show_in_menu' => 'edit.php' ) );
If you have a taxonomy registered to the custom post type it will need to be added to the page as well.
In
add_submenu_page()
the first argument is the page to assign it to and the last is the menu slug.add_action('admin_menu', 'my_admin_menu'); function my_admin_menu() { add_submenu_page('edit.php', 'Genre', 'Genre', 'manage_options', 'edit-tags.php?taxonomy=genre'); }
Adding a custom post type as a sub-menu of another custom post type
To add the pages to another custom post type include the post type's query string parameter along with the page names.
To add the CPT Movies and its taxonomy Genre under the post type Entertainment adjust the code like this.
edit.php
becomesedit.php?post_type=entertainment
edit-tags.php
becomesedit-tags.php?taxonomy=genre&post_type=entertainment
register_post_type( 'movies', array( 'labels' => array( 'name' => __( 'Movies' ), 'singular_name' => __( 'Movie' ) ), 'public' => true, 'has_archive' => true, 'show_in_menu' => 'edit.php?post_type=entertainment' ) ); add_action('admin_menu', 'my_admin_menu'); function my_admin_menu() { add_submenu_page('edit.php?post_type=entertainment', 'Genre', 'Genre', 'manage_options', 'edit-tags.php?taxonomy=genre&post_type=entertainment'); }
-
Salutmerci.Çamarche.Mais le sous-menu cpt aperdu son sous-menu.Hi, thanks. It works. But the sub menu cpt lost its submenu.
- 2
- 2013-08-18
- Ari
-
J'aimis àjourma réponse avec unmoyen d'inclure destaxonomies.I've update my answer with a way to include taxonomies.
- 0
- 2013-08-21
- epilektric
-
Salutmerci!J'avaistrouvé lemoyen de lefaire!Maispeut-être que le vôtre donnera unmeilleur résultat!Hi thanks you! I had found the way to do it! But may be yours will give a better result!
- 0
- 2013-08-21
- Ari
-
l'attribut `show_in_menu`,n'apasfonctionnépourmoi.the `show_in_menu` attribute, didn't worked for me.
- 0
- 2015-02-26
- Francisco Corrales Morales
-
Désolé de répéter.Pour que le sous-menuet lemenuparetn restenten surbrillance,vous devez donner à WPplus d'informations.Ok,leparamètre 'show_in_menu' rend le sous-menu courant/en surbrillance lorsque 'my_post_type'est à l'écran.Maintenant,nous devons également ajouter une autre action,quimettraen évidence lemenuparent.Vouspouvezessayer ceci: add_filter ('parent_file','menu_highlight'));functionmenu_highlight ($fichier_parent) {global $plugin_page,$post_type;if ('my_post_type'==$post_type) {$plugin_page='edit.php?post_type=my_post_type';//lenom du hook de sous-menu} return $parent_file;}Sorry for repeating. In order for the submenu and paretn menu to stay highlighted you need to give WP some more information. Ok, the 'show_in_menu' parameter makes the submenu to be current/highlighted when 'my_post_type' is on the screen. Now, we need also to add another action, that will highlight the parent menu. You could try this: add_filter( 'parent_file', 'menu_highlight' )); function menu_highlight( $parent_file ){ global $plugin_page, $post_type; if ('my_post_type' == $post_type) { $plugin_page = 'edit.php?post_type=my_post_type'; // the submenu hook name } return $parent_file; }
- 0
- 2017-05-26
- TomeeNS
-
- 2017-03-14
Notretype demessagepersonnalisé:
$args['show_in_menu'] = false; register_post_type('custom_plugin_post_type', $args);
Ajoutez-lepour letype demessagepersonnaliséexistant ("produit"parexemple):
$existing_CPT_menu = 'edit.php?post_type=product'; $link_our_new_CPT = 'edit.php?post_type=custom_plugin_post_type'; add_submenu_page($existign_CPT_menu, 'SubmenuTitle', 'SubmenuTitle', 'manage_options', $link_our_new_CPT);
Ou ajoutezpournotremenu depluginpersonnalisé:
// Create plugin menu add_menu_page('MyPlugin', 'MyPlugin', 'manage_options', 'myPluginSlug', 'callback_render_plugin_menu'); // Create submenu with href to view custom_plugin_post_type $link_our_new_CPT = 'edit.php?post_type=custom_plugin_post_type'; add_submenu_page('myPluginSlug', 'SubmenuTitle', 'SubmenuTitle', 'manage_options', $link_our_new_CPT);
Our custom post type:
$args['show_in_menu'] = false; register_post_type('custom_plugin_post_type', $args);
Add him for existing Custom Post Type ("product" for example):
$existing_CPT_menu = 'edit.php?post_type=product'; $link_our_new_CPT = 'edit.php?post_type=custom_plugin_post_type'; add_submenu_page($existign_CPT_menu, 'SubmenuTitle', 'SubmenuTitle', 'manage_options', $link_our_new_CPT);
Or add for our custom plugin menu:
// Create plugin menu add_menu_page('MyPlugin', 'MyPlugin', 'manage_options', 'myPluginSlug', 'callback_render_plugin_menu'); // Create submenu with href to view custom_plugin_post_type $link_our_new_CPT = 'edit.php?post_type=custom_plugin_post_type'; add_submenu_page('myPluginSlug', 'SubmenuTitle', 'SubmenuTitle', 'manage_options', $link_our_new_CPT);
-
Merci!C'est utilepourmoi.Thanks! It's helpful for me.
- 0
- 2019-11-27
- NSukonny
Je développe actuellement unplugin wordpress qui utilise deuxtypes depublicationpersonnalisés.Ce queje veux savoirici:est-ilpossible d'ajouter unmenu detype d'articlepersonnalisé comme sous-menu d'un autretype d'articlepersonnalisé?