Home › Forum › Problemi Vari con WP › aggiungere menu personalizzato al tema
-
AutorePost
-
-
23 Luglio 2010 alle 12:06 #14558peopleatworkPartecipante
Rimando il messaggio perchè non sono venute la parti di codice
Ho wordpress 3.0 e ho installato un tema per il quale non sono previsti menu personalizzati.
Ho trovato molte informazioni su come inserire la possibilità di personalizzare il menu ma con nessuna di questa riesco a farlo funzionare.
Nel file functions.php ho aggiunto:
if ( function_exists( ‘register_nav_menus’ ) ) {
register_nav_menus( array(‘primary’ => __( ‘Primary Navigation’) ) );
}
Non ho aggiunto l’istruzione:
add_theme_support(‘nav-menus’);
perchè in questa pagina del codex ho trovato che non è necessario in quanto la funzione register_nav_menus registra automaticamente il supporto per i menu personalizzati.
E cosଠfacendo non ho più la scritta “questo tema non supporta la personalizzazione dei menu…”
Poi ho aggiunto in headers.php l’istruzione per richiamare il mio menu
Ho fatto diverse prove:
1)<?php wp_nav_menu(); ?> dovrebbe farmi vedere il menu tradizionale —> non funziona
2)<?php wp_nav_menu( array(‘theme_location’ => ‘primary’ )); ?> dovrebbe richiamare il mio menu –> non funziona
3)<?php wp_nav_menu( array(‘menu’ => ‘menu1’ )); ?> dovrebbe richiamare il mio menu –> non funziona
Qualcuno di voi ha dovuto fare la stessa cosa?
Mi potete dare una mano?
Grazie
-
24 Luglio 2010 alle 15:56 #75485GRlabPartecipante
Se non hai esigenze particolare usa:
-
24 Luglio 2010 alle 16:39 #75490zhenyaPartecipante
Nel functions.php
add_theme_support( 'nav-menus' );
Twentyten usa questo in header.php
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
e theme location per la chiamata al menù
<?php wp_nav_menu( array( 'theme_location' => 'main', 'sort_column' => 'menu_order', 'fallback_cb' => 'display_home' ) ); ?>
Puoi aggiungere il fallback_cb per mostrare come controllare il callback di default se non è stato creato alcun menù. Se non includi il callback allora sarà il
wp_page_menu()
che giusto stampa la lista delle tue pagine.Puoi assegnando una funzione chiamata
display_home()
come tuo callback, tipo questa, che mostrerà il link alla home e 5 categoriefunction display_home() {
echo '<div class="navigation">
- Home
';
wp_list_categories('title_li=&depth=1&number=5');
echo '
</div>';
}
-
24 Luglio 2010 alle 16:49 #75492zhenyaPartecipante
“@edit
Tra navigation la parola Home e subito dopo questa, mancano un paio di pezzi del codice.. credo non sia possibile postarlo qui..
-
25 Luglio 2010 alle 9:34 #75511peopleatworkPartecipante
Come dicevo sopra non ho messo l’istruzione:
add_theme_support(‘nav-menus’);
perchè in questa pagina del codex ho trovato che non è necessario in quanto la funzione register_nav_menus registra automaticamente il supporto per i menu personalizzati.
E in effetti con le istruzioni riportate sopra riesco a far sparire il messaggio dei menu personalizzati non supportati e posso quindi procedere con la creazione dei miei menu
Quello che non funziona è la parte dopo, credo
Non uso Twentyten ma un tema (Flex) che ho acquistato
nella header.php sostituirei la riga:
<?php wp_list_categories(‘sort_column=name&title_li=&depth=2’); ?>
con questa:
?php wp_nav_menu( array(‘menu’ => ‘menu1’ )); ?>
oppure questa:
<?php wp_nav_menu( array(‘theme_location’ => ‘primary’ )); ?>
ma non funziona
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.