Comment ajouter une page de sous-menu à un type de publication personnalisé?
-
-
Jepense que vouspassez une limaceparentincorrecte,c'est-à-dire desportefeuilles.vérifiez-le ànouveau ... à laplace desportefeuilles,passez le slug de votretype depublicationpersonnalisé.i think you are passing incorrent parent slug, i.e portfolios. check it again... inplace of portfolios pass the slug of your custom post type..
- 0
- 2013-08-23
- Prince Singh
-
4 réponses
- votes
-
- 2012-12-15
add_options_page()
l'ajoute automatiquement sous lesparamètres,cependantadd_submenu_page()
vous donne le contrôle de l'endroit oùvous voulez qu'il apparaisse.Essayez quelque chose comme ceci:
add_submenu_page( 'edit.php?post_type=portfolios', __( 'Test Settings', 'menu-test' ), __( 'Test Settings', 'menu-test' ), 'manage_options', 'testsettings', 'mt_settings_page' );
add_options_page()
automatically adds it underneath settings, howeveradd_submenu_page()
gives you control as to where you want it to show up.Try something like this:
add_submenu_page( 'edit.php?post_type=portfolios', __( 'Test Settings', 'menu-test' ), __( 'Test Settings', 'menu-test' ), 'manage_options', 'testsettings', 'mt_settings_page' );
-
Votre codene fonctionnera que si vousmanquez untroisième argument de `menu_title`.Voir le codexYour code won't work unless, you're missing an third argument of `menu_title`. See the codex
- 1
- 2013-11-02
- Rahil Wazir
-
- 2017-01-03
add_submenu_page('edit.php?post_type='.$this->plugin->posttype, __('Settings', $this->plugin->name), __('Settings', $this->plugin->name), 'manage_options', $this->plugin->name, array(&$this, 'adminPanel'));
il y apanneau d'administrationest unnom defonction de rappel.
add_submenu_page('edit.php?post_type='.$this->plugin->posttype, __('Settings', $this->plugin->name), __('Settings', $this->plugin->name), 'manage_options', $this->plugin->name, array(&$this, 'adminPanel'));
there is admin panel is a callback function name.
-
Pouvez-vousexpliquer unpeuplus?Can you explain a little bit more?
- 1
- 2017-01-03
- bravokeyl
-
- 2018-01-20
Pour développer l'exemple @Jai ...
Mesparamètres
$postType = 'foo'; $categoryType = 'bar';
Type demessagepersonnalisé
$args = array( 'labels' => array('name'=>$postType, ...), 'rewrite' => array('slug' => 'all-'.$postType), 'taxonomies' => array($categoryType) ); register_post_type( 'foo', $args );
Taxonomie des catégoriespersonnalisées
$args = array( 'labels' => array( 'name' => _x( $categoryType, 'taxonomy general name' )), 'rewrite' => array( 'slug' => $categoryType ), ); register_taxonomy( $categoryType, array( $postType ), $args );
Ajouter des catégories comme éléments de sous-menu
$wp_term = get_categories( 'taxonomy='.$categoryType.'&type='.$postType ); if ( $wp_term ) { foreach ( $wp_term as $term ) { // add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' ) add_submenu_page( 'edit.php?post_type='.$postType, $term->name, $term->name, 'manage_options', 'edit.php?post_type='.$postType.'&'.$categoryType.'='.$term->slug, ''); } }
To expand on @Jai example...
My Settings
$postType = 'foo'; $categoryType = 'bar';
Custom Post Type
$args = array( 'labels' => array('name'=>$postType, ...), 'rewrite' => array('slug' => 'all-'.$postType), 'taxonomies' => array($categoryType) ); register_post_type( 'foo', $args );
Custom Category Taxonomy
$args = array( 'labels' => array( 'name' => _x( $categoryType, 'taxonomy general name' )), 'rewrite' => array( 'slug' => $categoryType ), ); register_taxonomy( $categoryType, array( $postType ), $args );
Add Categories as submenu items
$wp_term = get_categories( 'taxonomy='.$categoryType.'&type='.$postType ); if ( $wp_term ) { foreach ( $wp_term as $term ) { // add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' ) add_submenu_page( 'edit.php?post_type='.$postType, $term->name, $term->name, 'manage_options', 'edit.php?post_type='.$postType.'&'.$categoryType.'='.$term->slug, ''); } }
-
- 2018-10-21
/** * Adds a submenu page under a custom post type parent. */ function books_register_ref_page() { add_submenu_page( 'edit.php?post_type=book', __( 'Books Shortcode Reference', 'textdomain' ), __( 'Shortcode Reference', 'textdomain' ), 'manage_options', 'books-shortcode-ref', 'books_ref_page_callback' ); } /** * Display callback for the submenu page. */ function books_ref_page_callback() { ?> <div class="wrap"> <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1> <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p> </div> <?php }
Lien vers la source ,auteur: Christina Blust
/** * Adds a submenu page under a custom post type parent. */ function books_register_ref_page() { add_submenu_page( 'edit.php?post_type=book', __( 'Books Shortcode Reference', 'textdomain' ), __( 'Shortcode Reference', 'textdomain' ), 'manage_options', 'books-shortcode-ref', 'books_ref_page_callback' ); } /** * Display callback for the submenu page. */ function books_ref_page_callback() { ?> <div class="wrap"> <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1> <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p> </div> <?php }
Link to Source , Author: Christina Blust
J'essaie de créer un sous-menu sous untype depublicationpersonnalisé quej'ainommé Portfolios.
Lorsqueje change
add_submenu_page()
enadd_options_page()
,unnouveau lien apparaît correctement dans lemenu Paramètres,maisiln'apparaîtpas sous lemenu Portefeuilles.Qu'est-ce queje fais demal?
Voicimonextrait de code;