Le menu n'est pas visible en apparence
1 réponses
- votes
-
- 2014-09-08
J'aifait une réponse complète à ce sujetil y a quelquetemps sur SO. Vouspouvez voir l'article complet ici . Dans l'intérêt des utilisateurs de WPSE,j'ai copiéma réponse àpartir de cemessage. Jene l'aipasmodifié,cet article concernait à l'origine l'ajoutet l'affichage d'unmenu denavigation aupied depage,mais lamêmeméthodeexacte s'appliquepour unmenu denavigation d'en-tête. J'espère que voustrouverez cela utile
POSTE ORIGINAL DE SO
Vous avez correctementenregistré vos deuxmenus denavigation. Jefaistoujours cela dansmon hook de configuration dethèmeinitial quiest accroché au hook
after_setup_theme
. Doncje ferais quelque chose comme ça dans votrefunctions.php:function pietergoosen_theme_setup() { register_nav_menus( array( 'header' => 'Header menu', 'footer' => 'Footer menu' ) ); } add_action( 'after_setup_theme', 'pietergoosen_theme_setup' );
Gardez à l'esprit que vousn'êtespas obligé deprocéder de cettefaçon. Ce qui suitfonctionne également
register_nav_menus( array( 'header' => 'Header menu', 'footer' => 'Footer menu' ) );
Vous devriezmaintenant voir les deuxmenus dans lebackend sous "Apparence> Menus> Gérer lesemplacements" (Uniquement si unmenuexiste)
Pour lesbesoins dumenu dupied depage,ajoutez le code suivant dans votrepied depage où vous devez afficher lemenu:
<nav id="footer-navigation" class="site-navigation footer-navigation" role="navigation"> <?php wp_nav_menu( array( 'theme_location' => 'footer', 'menu_class' => 'nav-menu', 'fallback_cb' => false ) ); ?> </nav>
À ce stade,rienne sera affiché,et jepense que c'est là que vous êtes égalementbloqué. La raisonen est qu'iln'y a aucun élément affecté aumenu,et si rienn'est affecté à unmenu,rienne sera affiché. Nous devons doncinsérer quelque chose à afficher.
Dans lebackend,accédez à "Apparence> Menus> Modifier lesmenus". Dans le champ "Nom dumenu",entrez unnompour votremenuet cliquez sur "Créer unmenu". Vouspourrezmaintenant ajouter lemenu dans l'écran demenu.
Vouspouvezmaintenant choisir des éléments du côtégauche àinsérer dans votremenu. Vouspouvez également définir l'emplacement dumenu,dans ce cas dans lepied depage. J'ai choisi d'afficher les catégories dans lepied depage. Cliquez sur "Enregistrer lemenu" lorsque vous avezterminé.
Vous devriezmaintenant voir votremenu denavigation dans lefront-end.
Il vous suffit d'ajouter du style à votrebarre denavigationmaintenant. Vousferezexactement lamême chosepour lemenu denavigation de l'en-tête,acceptez que vous ajoutiez l'appel aumenu dans le header.php. J'espère que voustrouverez cela utile.
I have done a complete answer on this a while ago on SO. You can see the complete post here. For the sake of WPSE users, I have copied my answer from that post. I have not edited it, this post was originally about adding and displaying a nav menu to the footer, but the same exact method applies for a header nav menu. I hope you find this helpful
ORIGINAL POST FROM SO
You have registered you two nav menus correctly. I always do that within my initial theme setup hook that gets hooked to the
after_setup_theme
hook. So I would do something like this in your functions.php:function pietergoosen_theme_setup() { register_nav_menus( array( 'header' => 'Header menu', 'footer' => 'Footer menu' ) ); } add_action( 'after_setup_theme', 'pietergoosen_theme_setup' );
Keep in mind, you don't have to do it this way. The following also works
register_nav_menus( array( 'header' => 'Header menu', 'footer' => 'Footer menu' ) );
You should now see the two menus in the backend under "Appearance > Menus > Manage Locations" (Only if a menu exist)
For the sake of the footer menu, add the following code in your footer where you need to display the menu:
<nav id="footer-navigation" class="site-navigation footer-navigation" role="navigation"> <?php wp_nav_menu( array( 'theme_location' => 'footer', 'menu_class' => 'nav-menu', 'fallback_cb' => false ) ); ?> </nav>
At this stage nothing will be displayed, and I think this is where you also get stuck at. The reason for this is that there aren't any items assigned to the menu, and if there are nothing assigned to a menu, then nothing will be displayed. So we have to insert something to be displayed.
In the backend, go to "Appearance > Menus > Edit Menus". In the "Menu Name" field, enter a name for your menu and click "Create Menu". You will now be able to add the menu in the menu screen.
You can now choose items from the left hand side to insert into your menu. You can also set the location of the menu, in this case in the footer. I've selected to display the categories in the footer. Click "Save Menu" when done.
You should now see your nav menu in the front end.
You just have to add styling to your nav bar now. You will do exactly the same for the header nav menu, accept you will add the call to the menu in the header.php. I hope you find this usefull.
-
J'aifait ce que vous avezexpliquémaisil y atoujours lemême résultat :(I did as you explained but still there is same result :(
- 0
- 2014-09-08
- Rohil_PHPBeginner
-
Votrefichier s'appelle-t-ilfunction.php oufunctions.phpIs your file called function.php or functions.php
- 0
- 2014-09-08
- Pieter Goosen
-
C'estfunctions.php ...It is functions.php ...
- 0
- 2014-09-08
- Rohil_PHPBeginner
-
Quelle (s)erreur (s) obtenez-vous.Ce quine sepassepas devrait,ou ce quine devraitpas sepasser.S'il vousplaît,expliquezWhat error/s are you getting. What is not happening that should, or what is happening that shouldn't. Please explain
- 0
- 2014-09-08
- Pieter Goosen
-
J'ai les solutions!Mercipour votretemps. Vous devez du café :)Got the solutions ! Thanks for your time .You owe coffee :)
- 1
- 2014-09-08
- Rohil_PHPBeginner
-
Veuillezexpliquer ce qui a changé ou quelle a été la solution?Please explain what changed, or what the solution was?
- 0
- 2019-02-13
- Lee
J'ai ajouté le code suivant àma
function.php
Et voicimon code où setrouve lemenu.
Quelpourrait être leproblème?