Come Aggiungere una Pagina Sottomenu a un Tipo di Post Personalizzato?
22 ago 2012, 16:06:28
Visualizzazioni: 58.2K
Voti: 24
Sto cercando di creare un sottomenu sotto un Tipo di Post Personalizzato (Custom Post Type) che ho chiamato Portfolios.
Quando cambio add_submenu_page()
in add_options_page()
, viene correttamente mostrato un nuovo link sotto il menu Impostazioni, ma non appare sotto il menu Portfolios.
Cosa sto sbagliando?
Di seguito il mio frammento di codice:
add_action( 'admin_menu', 'mt_add_pages' );
function mt_add_pages() {
add_submenu_page(
__( 'portfolios', 'menu-test' ), // testo da tradurre
__( 'Impostazioni Test', 'menu-test' ), // testo da tradurre
'manage_options',
'testsettings',
'mt_settings_page'
);
function mt_settings_page() {
echo "<h2>" . __( 'Impostazioni Test', 'menu-test' ) . "</h2>";
}
}

zoaCode
343
Commenti
Tutte le risposte alla domanda
4
1
add_options_page()
aggiunge automaticamente la voce sotto Impostazioni, mentre add_submenu_page()
ti dà il controllo su dove vuoi che appaia.
Prova qualcosa del genere:
add_submenu_page(
'edit.php?post_type=portfolios',
__( 'Impostazioni di Test', 'menu-test' ),
__( 'Impostazioni di Test', 'menu-test' ),
'manage_options',
'testsettings',
'mt_settings_page'
);

NightHawk
1.47K
15 dic 2012 06:22:45
0
Per ampliare l'esempio di @Jai...
Le mie impostazioni
$postType = 'foo';
$categoryType = 'bar';
Tipo di post personalizzato
$args = array(
'labels' => array('name'=>$postType, ...),
'rewrite' => array('slug' => 'all-'.$postType),
'taxonomies' => array($categoryType)
);
register_post_type( 'foo', $args );
Tassonomia personalizzata per le categorie
$args = array(
'labels' => array( 'name' => _x( $categoryType, 'taxonomy general name' )),
'rewrite' => array( 'slug' => $categoryType ),
);
register_taxonomy( $categoryType, array( $postType ), $args );
Aggiungi le categorie come voci del sottomenu
$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, '');
}
}

Artistan
233
20 gen 2018 20:39:45
0
/**
* Aggiunge una pagina di sottomenu sotto un tipo di post personalizzato come genitore.
*/
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'
);
}
/**
* Callback per visualizzare la pagina di sottomenu.
*/
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 alla Fonte , Autore: Christina Blust

Lincoln Lemos
151
21 ott 2018 07:38:08
Domande correlate
9
risposte