Afficher une partie / branche de l'arborescence du menu en utilisant wp_nav_menu ()
-
-
Vous souhaitez donc conserver lemenuentieren tant quemenupersonnalisé,mais créer unmarcheurpersonnalisé qui l'afficheen développant uniquement le sous-arbre actif?Comme [ce code] (http://wordpress.mfields.org/2010/selective-page-hierarchy-for-wp_list_pages/),maisen étendant wp_nav_menu au lieu de wp_list_pages?J'ai récemmentfait quelque chose de similaireet jepourraispublier le code si c'est ce que vous recherchez ...So you want to maintain the entire menu as a custom menu, but create a custom walker which displays it expanding only the active subtree? Like [this code](http://wordpress.mfields.org/2010/selective-page-hierarchy-for-wp_list_pages/), but extending wp_nav_menu instead of wp_list_pages? I recently did something similar and could post the code if thats what you're looking for...
- 2
- 2010-10-12
- goldenapples
-
@goldenapples,c'estexactement ce queje recherche.Si celane vous dérangepas deposter votre code comme réponse,je vousen seraistrès reconnaissant.@goldenapples, that's exactly what I am after. If you don't mind posting your code as an answer I would be very grateful.
- 1
- 2010-10-12
- jessegavin
-
Jeme demande qu'unefonctionnalité aussi utile évidentene soitpas déjà la construire.C'estglobalementtrès utilepourtout site quifait du "CMS".I wonder that such a obvious useful functionality is not already build it. That's overall very useful for any site that does "CMS".
- 1
- 2011-02-09
- hakre
-
J'essaye de résoudre leproblème ci-dessus ou quelque chose de similaire.Comme alternative,j'aiproposé une solution CSSici: http://stackoverflow.com/q/7640837/518169I'm trying to solve the above problem or something similar. As an alternative I came up with a CSS solution here: http://stackoverflow.com/q/7640837/518169
- 0
- 2011-10-03
- hyperknot
-
10 réponses
- votes
-
- 2010-10-12
C'étaittoujours dansmonesprit alorsje l'ai revisitéet misen place cette solution,quine reposepasbeaucoup sur le contexte:
add_filter( 'wp_nav_menu_objects', 'submenu_limit', 10, 2 ); function submenu_limit( $items, $args ) { if ( empty( $args->submenu ) ) { return $items; } $ids = wp_filter_object_list( $items, array( 'title' => $args->submenu ), 'and', 'ID' ); $parent_id = array_pop( $ids ); $children = submenu_get_children_ids( $parent_id, $items ); foreach ( $items as $key => $item ) { if ( ! in_array( $item->ID, $children ) ) { unset( $items[$key] ); } } return $items; } function submenu_get_children_ids( $id, $items ) { $ids = wp_filter_object_list( $items, array( 'menu_item_parent' => $id ), 'and', 'ID' ); foreach ( $ids as $id ) { $ids = array_merge( $ids, submenu_get_children_ids( $id, $items ) ); } return $ids; }
Utilisation
$args = array( 'theme_location' => 'slug-of-the-menu', // the one used on register_nav_menus 'submenu' => 'About Us', // could be used __() for translations ); wp_nav_menu( $args );
This was still on my mind so I revisited it and put together this solution, that does not rely on context that much:
add_filter( 'wp_nav_menu_objects', 'submenu_limit', 10, 2 ); function submenu_limit( $items, $args ) { if ( empty( $args->submenu ) ) { return $items; } $ids = wp_filter_object_list( $items, array( 'title' => $args->submenu ), 'and', 'ID' ); $parent_id = array_pop( $ids ); $children = submenu_get_children_ids( $parent_id, $items ); foreach ( $items as $key => $item ) { if ( ! in_array( $item->ID, $children ) ) { unset( $items[$key] ); } } return $items; } function submenu_get_children_ids( $id, $items ) { $ids = wp_filter_object_list( $items, array( 'menu_item_parent' => $id ), 'and', 'ID' ); foreach ( $ids as $id ) { $ids = array_merge( $ids, submenu_get_children_ids( $id, $items ) ); } return $ids; }
Usage
$args = array( 'theme_location' => 'slug-of-the-menu', // the one used on register_nav_menus 'submenu' => 'About Us', // could be used __() for translations ); wp_nav_menu( $args );
-
Belletechnique!Puis-je demander quelque chose concernant celui-ci: comment afficheriez-vous le contenu de cespages de sous-menu répertoriées dans unmodèle?Lovely technique! May I ask something possibly regarding to this one: How would you display content of those listed submenu pages in template?
- 0
- 2012-08-22
- daniel.tosaba
-
@ daniel.tosaba vous devrez sous-classer ou utiliser desfiltres dans la classe `Walker_Nav_Menu`.Commetous lesmenus,troppour les commentaires -poser unenouvelle question à ce sujet?@daniel.tosaba you will need to subclass or use filters in `Walker_Nav_Menu` class. Like all menu stuff too much for comment - ask new question about it?
- 2
- 2012-08-22
- Rarst
-
http://wordpress.stackexchange.com/questions/62758/display-content-of-child-linkshttp://wordpress.stackexchange.com/questions/62758/display-content-of-child-links
- 0
- 2012-08-23
- daniel.tosaba
-
Une réponsetellementfantastique.Mercibeaucoup.Cela devrait vraiment être une optionpar défaut dans WordPress.Such a fantastic answer. Thank you so much. This should really be a default option within WordPress.
- 3
- 2012-09-11
- dotty
-
Hmm,j'aien fait unproblème étrange.J'ai unepageintitulée "Enfants".Etil semble que l'apostrophe dans lemotne trouvepas lapage.Desidées?Hmm, I actually have a strange problem. I have a page called "Children's". And it seems that the apostrophe in the word fails to find the page. Any ideas?
- 0
- 2012-09-11
- dotty
-
@dotty Jene me souvienspas de ce quiestprécisément stocké dans le champpar lequel le codefiltre.Ilpeut s'agir d'une versionnettoyée ou échappéepar unebarre oblique dutitre.@dotty I don't remember what precisely is stored in field the code filters by. It might be sanitized or slash-escaped version of the title.
- 0
- 2012-09-11
- Rarst
-
désolé,je ne suispas sûr de ce que vous voulez dire.Pourriez-vous clarifier s'il vousplaît.sorry, I'm not sure what you mean. Could you clarify please.
- 0
- 2012-09-13
- dotty
-
@dotty,ilpeut être stocké comme `Children \ 's` ou quelque chose comme ça,je n'aipas ce code configurépour letestpour lemoment ...@dotty it might be stored like `Children\'s` or something like that, I don't have this code set up for test right now...
- 0
- 2012-09-13
- Rarst
-
Il semble que celane fonctionneplus dans WP 4. J'obtiens cetteerreur: Standards stricts: Seules les variables doivent êtrepasséespar référence dans ->en ligne -> $parent_id=array_pop (wp_filter_object_list ($items,array ('title'=> $args-> sous-menu),'et','ID'));Looks like this no longer works in WP 4. I get this error: Strict Standards: Only variables should be passed by reference in -> on line -> $parent_id = array_pop( wp_filter_object_list( $items, array( 'title' => $args->submenu ), 'and', 'ID' ) );
- 0
- 2014-09-05
- gdaniel
-
@gdanieltesté - celafonctionneet n'a rien à voir avec lamise àjour de WP,juste unpetit ajustementpour être un code PHPplus approprié :)@gdaniel tested – it does work and has nothing to do with WP update, just needed a small tweak to be more proper PHP code :)
- 0
- 2014-09-05
- Rarst
-
Bizarre.Tousmes sous-menus utilisant cettefonction ont disparujuste après lamise àjour vers wp 4. Merci d'avoirjeté un coup d'œil.Je vais vérifierpour voirtout ce qui auraitpu arriver.Weird. All my submenus using that function disappeared right after I updated to wp 4. Thanks for taking a look though. I will check to see whatever else could have happened.
- 0
- 2014-09-05
- gdaniel
-
J'ai découvertmonproblème.J'utilisais l'argumentmenu=> "menu-name" dans wp_nav_menu ... J'ai supprimé 'menu'et ajoutétheme_location,et toutest revenu à lanormale.I figured out my issue. I was using the argument menu => "menu-name" in wp_nav_menu... I removed 'menu' and added theme_location, and everything went back to normal.
- 0
- 2014-09-05
- gdaniel
-
Solutionfantastique,@Rarst!Commetoujours.Fantastic solution, @Rarst! As always.
- 0
- 2015-02-24
- Eric Holmes
-
Hé @Rarst,tuflottestoujours au sommet dans denombreuxendroits sur cette réponse.La version acceptée devrait vraiment être réécritepourtenir compte desmarcheurs denavigationpersonnalisés,car onpourrait simplementfiltrerpour "élément demenu actuel","menu-actuel-parent"et "ancêtre-menu-courant"puis afficher le sous-menu.Pas defiltres,pas de hacks.Hey @Rarst, you're still floating to the top in a lot of places on this answer. The accepted version should really be rewritten to account for custom nav walkers, since one could just filter for "current-menu-item", "current-menu-parent", and "current-menu-ancestor" then render out the submenu. No filters, no hacks.
- 0
- 2015-03-10
- Imperative Ideas
-
@ImperativeIdeas Ma réponse affiche labranche _arbitrary_parnom,pas seulement labranche actuelle.@ImperativeIdeas My answer displays _arbitrary_ branch by name, not just current one.
- 0
- 2015-03-10
- Rarst
-
Vraimentbien.Si quelqu'unestintéressé,pourfaire lamême chosemaispar ID depage,changez la ligne `wp_filter_object_list`en` wp_filter_object_list ($items,array ('object_id'=> $ args-> submenu),'et','ID');»Really neat. If anyone is interested, to do the same but by page ID, change the `wp_filter_object_list` line to `wp_filter_object_list( $items, array( 'object_id' => $args->submenu ), 'and', 'ID' );`
- 3
- 2015-04-30
- Ben
-
- 2011-02-07
@goldenapples: Votre classe Walker ne fonctionnepas. Mais l'idéeest vraimentbonne. J'ai créé unmarcheurbasé sur votreidée:
La classeclass Selective_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter return $output; if (empty($elements)) //nothing to walk return $output; $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if ( -1 == $max_depth ) { $empty_array = array(); foreach ( $elements as $e ) $this->display_element( $e, $empty_array, 1, 0, $args, $output ); return $output; } /* * need to display in hierarchical order * separate elements into two buckets: top level and children elements * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( 0 == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } /* * when none of the elements is top level * assume the first one must be root of the sub elements */ if ( empty($top_level_elements) ) { $first = array_slice( $elements, 0, 1 ); $root = $first[0]; $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( $root->$parent_field == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } } $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); //added by continent7 foreach ( $top_level_elements as $e ){ //changed by continent7 // descend only on current tree $descend_test = array_intersect( $current_element_markers, $e->classes ); if ( !empty( $descend_test ) ) $this->display_element( $e, $children_elements, 2, 0, $args, $output ); } /* * if we are displaying all levels, and remaining children_elements is not empty, * then we got orphans, which should be displayed regardless */ /* removed by continent7 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { $empty_array = array(); foreach ( $children_elements as $orphans ) foreach( $orphans as $op ) $this->display_element( $op, $empty_array, 1, 0, $args, $output ); } */ return $output; } }
Vouspouvezmaintenant utiliser:
<?php wp_nav_menu( array( 'theme_location'=>'test', 'walker'=>new Selective_Walker() ) ); ?>
La sortieest une liste contenant l'élément racine actuelet sesenfants (pas leursenfants). Def: Élément racine:=L'élément demenu deniveau supérieur qui correspond à lapage actuelle ouest leparent d'unepage actuelle ou unparent d'unparent ...
Celane répondpasexactement à la questioninitialemaispresque,caril y atoujours l'élément depremierniveau. Celame convient,carje veux l'élément deniveau supérieur commetitre de labarre latérale. Si vous voulez vousen débarrasser,vous devrezpeut-être remplacer display_element ou utiliser un analyseur HTML.
@goldenapples: Your Walker Class does not work. But the idea is really good. I created a walker based on your idea:
class Selective_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter return $output; if (empty($elements)) //nothing to walk return $output; $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if ( -1 == $max_depth ) { $empty_array = array(); foreach ( $elements as $e ) $this->display_element( $e, $empty_array, 1, 0, $args, $output ); return $output; } /* * need to display in hierarchical order * separate elements into two buckets: top level and children elements * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( 0 == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } /* * when none of the elements is top level * assume the first one must be root of the sub elements */ if ( empty($top_level_elements) ) { $first = array_slice( $elements, 0, 1 ); $root = $first[0]; $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( $root->$parent_field == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } } $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); //added by continent7 foreach ( $top_level_elements as $e ){ //changed by continent7 // descend only on current tree $descend_test = array_intersect( $current_element_markers, $e->classes ); if ( !empty( $descend_test ) ) $this->display_element( $e, $children_elements, 2, 0, $args, $output ); } /* * if we are displaying all levels, and remaining children_elements is not empty, * then we got orphans, which should be displayed regardless */ /* removed by continent7 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { $empty_array = array(); foreach ( $children_elements as $orphans ) foreach( $orphans as $op ) $this->display_element( $op, $empty_array, 1, 0, $args, $output ); } */ return $output; } }
Now you can use:
<?php wp_nav_menu( array( 'theme_location'=>'test', 'walker'=>new Selective_Walker() ) ); ?>
The output is a list containing the current root element and it's children (not their children). Def: Root element := The top level menu item that corresponds to the current page or is parent of a current page or a parent of a parent ...
This does not exactly answer the original question but almost, since there is still the top level item. This is fine for me, because I want the top level element as a headline of the sidebar. If you want to get rid of this, you might have to override display_element or use a HTML-Parser.
-
- 2010-10-12
Bonjour @jessegavin :
Lesmenus denavigation sont stockés dans une combinaison detypes d'articlespersonnaliséset detaxonomiespersonnalisées. Chaquemenuest stockéen tant queterme (c'est-à-dire "About Menu" ,trouvé dans
wp_terms
) d'unetaxonomiepersonnalisée (c'est-à-direnav_menu
,trouvé dans < code> wp_term_taxonomy .)Chaque élément dumenu denavigationest stockéen tant quemessage de
post_type=='nav_menu_item'
(c'est-à-dire "Àpropos de l'entreprise" ,trouvé danswp_posts
) avec ses attributs stockésen tant quepostmeta (danswp_postmeta
)en utilisant unpréfixemeta_key
de_menu_item_ *
où_menu_item_menu_item_parent
est l'ID de lapublication de l'élément demenu denavigationparent de votre élément demenu.La relationentre lesmenuset les éléments demenuest stockée dans
wp_term_relationships
oùobject_id
se rapporte à$post- > ID
pour lemenu denavigation L'élémentet le$term_relationships- >term_taxonomy_id
se rapportent aumenu défini collectivement danswp_term_taxonomy
etwp_terms
.Je suispresque sûr qu'il seraitpossible de accrocher à lafois
'wp_update_nav_menu'
et'wp_update_nav_menu_item'
pour créer desmenus réels danswp_terms
et unensembleparallèle de relations danswp_term_taxonomy
etwp_term_relationships
où chaque élément demenu denavigation qui a des sous-éléments demenu denavigation devient également sonpropremenu denavigation.Vous voudriez également hooker
'wp_get_nav_menus'
(quej'ai suggéré d'être ajouté à WP 3.0 sur labase d'untravail similaire queje faisais quelquesmois)il y a) pour vous assurer que vosmenus denavigationgénérésne sontpas affichéspour êtremanipuléspar l'utilisateur dans l'administrateur,sinonils se désynchroniseraienttrès rapidementet vous auriez alors un cauchemar de données sur votremain.Cela semble être unprojet amusantet utile,mais c'est unpeuplus de codeet detests queje nepeuxme permettre de résoudremaintenant,en partieparce quetout ce qui synchronise les données atendance à être un PITA lorsqu'il s'agit de corrigertous lesbogues (etparce que les clientspayantsme pressent defaire avancer les choses. :) Mais armé desinformations ci-dessus,je suis assezmotivépour qu'un développeur deplugins WordPresspuisse le coder s'ils le voulaient.
Bien sûr,vous réalisezmaintenant que si vous le codez,vous êtes obligé de leposterici afin quenouspuissionstousbénéficier de vos largesses! :-)
Hi @jessegavin:
Nav Menus are stored in a combination of custom post types and custom taxonomies. Each menu is stored as a Term (i.e. "About Menu", found in
wp_terms
) of a Custom Taxonomy (i.e.nav_menu
, found inwp_term_taxonomy
.)Each Nav Menu Item is stored as a post of
post_type=='nav_menu_item'
(i.e. "About the Firm", found inwp_posts
) with it's attributes stored as post meta (inwp_postmeta
) using ameta_key
prefix of_menu_item_*
where_menu_item_menu_item_parent
is the ID of your menu item's parent Nav Menu item post.The relationship between menus and menu items is stored in
wp_term_relationships
whereobject_id
relates to the$post->ID
for the Nav Menu Item and the$term_relationships->term_taxonomy_id
relates to the menu defined collectively inwp_term_taxonomy
andwp_terms
.I'm pretty sure it would be possible to hook both
'wp_update_nav_menu'
and'wp_update_nav_menu_item'
to create actual menus inwp_terms
and a parallel set of relations inwp_term_taxonomy
andwp_term_relationships
where every Nav Menu Item that has sub-Nav Menu items also becomes it's own Nav Menu.You'd also want to hook
'wp_get_nav_menus'
(which I suggested be added to WP 3.0 based on some similar work I was doing a few months ago) to ensure that your generated Nav Menus are not displayed for manipulation by the user in the admin, otherwise they'd get out of sync really fast and then you'd have a data nightmare on your hand.Sounds like a fun and useful project, but it is a little bit more code and testing than I can afford to tackle right now in part because anything that synchronizes data tends to be a PITA when it comes to ironing out all the bugs (and because paying clients are pressing me to get things done. :) But armed with the above info I'm pretty a motivated WordPress plugin developer could code it if they wanted to.
Of course you do realize now if you do code it you are obligated to post it back here so we can all benefit from your largesse! :-)
-
Jene suispas sûr de suivre ce que vous dites.Je recherche une solutionen lecture seulepour afficher des "sous-menus" liés à lapage actuelle d'un utilisateur.Parlons-nous de lamême chose?- J'apprécie cependant votreexplicationplus approfondie sur le schéma de labase de données.I am not sure that I am following what you're saying. I am looking for a read-only solution for displaying "sub-menus" related to the current page a user is at. Are we talking about the same thing? - I do appreciate your deeper explanation about the database schema though.
- 0
- 2010-10-14
- jessegavin
-
* @jessegavin * - Oui,si vous voulez appeler `wp_nav_menu ()` alors vous devrez cloner lesmenus car ** `wp_nav_menu ()`est étroitement couplé à la structure dumenu **.L'autre optionest de copier le code `wp_nav_menu ()`et d'apporter lesmodificationsnécessairespour l'afficher sousforme de sous-menu.*@jessegavin* - Yes, if you want to call `wp_nav_menu()` then you'll need to clone the menus because **`wp_nav_menu()` is tightly coupled to the menu structure**. The other option is to copy the `wp_nav_menu()` code and make the modifications required to display as a submenu.
- 0
- 2010-10-14
- MikeSchinkel
-
C'est la réponse quej'ai recherchéetoute lajournée,mercibeaucoup!This is the answer I've been looking for all day, thank you very much!
- 0
- 2019-12-13
- Chris Haas
-
- 2010-10-15
Ceciest uneextension demarcheur qui devraitfaire ce que vous recherchez:
La classeclass Selective_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter return $output; if (empty($elements)) //nothing to walk return $output; $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if ( -1 == $max_depth ) { $empty_array = array(); foreach ( $elements as $e ) $this->display_element( $e, $empty_array, 1, 0, $args, $output ); return $output; } /* * need to display in hierarchical order * separate elements into two buckets: top level and children elements * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( 0 == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } /* * when none of the elements is top level * assume the first one must be root of the sub elements */ if ( empty($top_level_elements) ) { $first = array_slice( $elements, 0, 1 ); $root = $first[0]; $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( $root->$parent_field == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } } $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); foreach ( $top_level_elements as $e ) { // descend only on current tree $descend_test = array_intersect( $current_element_markers, $e->classes ); if ( empty( $descend_test ) ) unset ( $children_elements ); $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output ); } /* * if we are displaying all levels, and remaining children_elements is not empty, * then we got orphans, which should be displayed regardless */ if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { $empty_array = array(); foreach ( $children_elements as $orphans ) foreach( $orphans as $op ) $this->display_element( $op, $empty_array, 1, 0, $args, $output ); } return $output; } }
Basé vaguement sur le code demfields auquelj'aifait référence dansmon commentaireplustôt. Tout ce qu'ilfaitest de vérifieren parcourant lemenupour voir si l'élément actuelest (1) l'élément demenu actuel,ou (2) un ancêtre de l'élément demenu actuel,et ne développe le sous-arbreen dessous que si l'une de ces conditionsest vraie . J'espère que celafonctionnepour vous.
Pour l'utiliser,il suffit d'ajouter un argument "walker" lorsque vous appelez lemenu,c'est-à-dire:
<?php wp_nav_menu( array( 'theme_location'=>'test', 'walker'=>new Selective_Walker() ) ); ?>
This is a walker extension which should do what you're looking for:
class Selective_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter return $output; if (empty($elements)) //nothing to walk return $output; $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if ( -1 == $max_depth ) { $empty_array = array(); foreach ( $elements as $e ) $this->display_element( $e, $empty_array, 1, 0, $args, $output ); return $output; } /* * need to display in hierarchical order * separate elements into two buckets: top level and children elements * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( 0 == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } /* * when none of the elements is top level * assume the first one must be root of the sub elements */ if ( empty($top_level_elements) ) { $first = array_slice( $elements, 0, 1 ); $root = $first[0]; $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( $root->$parent_field == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } } $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); foreach ( $top_level_elements as $e ) { // descend only on current tree $descend_test = array_intersect( $current_element_markers, $e->classes ); if ( empty( $descend_test ) ) unset ( $children_elements ); $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output ); } /* * if we are displaying all levels, and remaining children_elements is not empty, * then we got orphans, which should be displayed regardless */ if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { $empty_array = array(); foreach ( $children_elements as $orphans ) foreach( $orphans as $op ) $this->display_element( $op, $empty_array, 1, 0, $args, $output ); } return $output; } }
Based loosely on mfields' code I referenced in my comment earlier. All it does is check when walking the menu to see whether the current element is (1) the current menu item, or (2) an ancestor of the current menu item, and expands the subtree below it only if either of those conditions is true. Hope this works for you.
To use it, just add a "walker" argument when you call the menu, ie:
<?php wp_nav_menu( array( 'theme_location'=>'test', 'walker'=>new Selective_Walker() ) ); ?>
-
Oh ... Je viens de relire votre questionet j'ai réalisé queje l'avaismal comprise au début.Ceguide afficheratous les autres éléments demenu deniveau supérieur,maisne les développerapas.Cen'étaitpasexactement ce que vous vouliezfaire.Pourtant,ce codepeut êtremodifié comme vous le souhaitez.Regardez simplement laboucle àtravers `$top_level_elements`et ajoutez votrepropretest avant l'appel à` $this-> display_element`.Oh... I just re-read your question and realized that I had misunderstood it at first. This walker will show all the other top-level menu items, just not expand them. This wasn't exactly what you had wanted to do. Still, this code can be modified in any way you want. Just look at the loop through `$top_level_elements` and add your own test before the call to `$this->display_element`.
- 0
- 2010-10-16
- goldenapples
-
Est-ilpossible que cette classemontre laprofondeur de la sous-page actuelle?Autrement dit. Sij'ai uneprofondeur detroisniveaux ouplus,que letroisièmeniveauet les suivants sont affichéspour la (sous)page actuelle?Pour lemoment,ilne montre que A> B,et non> C (C étant letroisième (niveau)Is it possible to get this class to show the depth of the current subpage? That is.. If I have a depth of three or more levels, that the third and subsequent levels are shown for the current (sub)page? At the moment, it only shows A > B, and not > C (C being the third (level)
- 0
- 2011-02-20
- Zolomon
-
@Zolomon - Jene suispas sûr de comprendre votre question.Cela devrait développer l'arborescenceentière sousn'importe quel élément demenu avec les classes 'current-menu-item','current-menu-parent' ou 'current-menu-ancestor'.Lorsqueje leteste,il affichetous lesniveaux de sous-pages dans lemenu.Que cherchez-vous àfaire?@Zolomon - I'm not sure I understand your question. This should expand the entire tree under any menu item with the classes 'current-menu-item', 'current-menu-parent', or 'current-menu-ancestor'. When I test it, it displays all the levels of subpages in the menu. What are you looking to do?
- 0
- 2011-02-21
- goldenapples
-
Peut-être voulez-vouspasser unparamètre `depth` à l'appel à` wp_nav_menu`,au cas où votrethème supplanterait d'unemanière ou d'une autre la valeurpar défaut de 0 (affichertous lesniveaux)?Maybe you want to pass a `depth` parameter to the call to `wp_nav_menu`, in case your theme is somehow over-riding the default of 0 (show all levels)?
- 0
- 2011-02-21
- goldenapples
-
- 2011-04-21
Mise àjour: j'en aifait unplugin. Téléchargezici .
J'avaisbesoin de résoudre ceproblèmemoi-mêmeet j'aifini par écrire unfiltre sur les résultats de la recherche dans lemenu. Il vouspermet d'utiliser
wp_nav_menu
comme d'habitude,mais de choisir une sous-section dumenuen fonction dutitre de l'élémentparent. Ajoutez unparamètresubmenu
aumenu comme ceci:wp_nav_menu(array( 'menu' => 'header', 'submenu' => 'About Us', ));
Vouspouvezmême approfondirplusieursniveauxen mettant desbarres obliques:
wp_nav_menu(array( 'menu' => 'header', 'submenu' => 'About Us/Board of Directors' ));
Ou si vouspréférez avec untableau:
wp_nav_menu(array( 'menu' => 'header', 'submenu' => array('About Us', 'Board of Directors') ));
Il utilise une version slug dutitre,ce qui devrait le rendreindulgentpour des choses comme lesmajusculeset laponctuation.
Update: I made this into a plugin. Download here.
I needed to solve this myself and eventually wound up writing a filter on the results of the menu lookup. It lets you use
wp_nav_menu
as normal, but choose a sub-section of the menu based on the title of the parent element. Add asubmenu
parameter to the menu like so:wp_nav_menu(array( 'menu' => 'header', 'submenu' => 'About Us', ));
You can even go several levels deep by putting slashes in:
wp_nav_menu(array( 'menu' => 'header', 'submenu' => 'About Us/Board of Directors' ));
Or if you prefer with an array:
wp_nav_menu(array( 'menu' => 'header', 'submenu' => array('About Us', 'Board of Directors') ));
It uses a slug version of the title, which should make it forgiving of things like capitals and punctuation.
-
Est-ilpossible d'accéder au sous-menu viaid?Je veux dire l'identifiant de lapage ou l'identifiant de l'article.Is it possible to reach submenu via id? I mean page id, or post id.
- 0
- 2013-02-28
- Digerkam
-
split ()est obsolète,remplacez `$ loc=split ("/",$ loc);` dans lepluginpar `$ loc=preg_split (" ~/~ ",$ loc);`split() is deprecated, replace `$loc = split( "/", $loc );` in plugin with `$loc = preg_split( "~/~", $loc );`
- 0
- 2018-09-04
- Floris
-
Je suggérerais également de rendre $ submenufacultatif.Ainsi,vouspouveztoujours récupérer l'intégralité dumenuen cas debesoin.Ajoutez ceci aufiltreen haut: `if (! Isset ($ args-> submenu)) { return $items; } `I would also suggest making $submenu optional. So you can still fetch the entire menu when needed. Add this to the filter to the top: ` if ( ! isset( $args->submenu ) ) { return $items; }`
- 0
- 2018-09-04
- Floris
-
- 2012-01-31
J'ai organisé le cours suivantpourmoi-même. Iltrouvera leparent denavigation supérieur de lapageen cours,ou vouspouvez lui donner un ID denavigation supérieur cible dans le constructeur du walker.
La classeclass Walker_SubNav_Menu extends Walker_Nav_Menu { var $target_id = false; function __construct($target_id = false) { $this->target_id = $target_id; } function walk($items, $depth) { $args = array_slice(func_get_args(), 2); $args = $args[0]; $parent_field = $this->db_fields['parent']; $target_id = $this->target_id; $filtered_items = array(); // if the parent is not set, set it based on the post if (!$target_id) { global $post; foreach ($items as $item) { if ($item->object_id == $post->ID) { $target_id = $item->ID; } } } // if there isn't a parent, do a regular menu if (!$target_id) return parent::walk($items, $depth, $args); // get the top nav item $target_id = $this->top_level_id($items, $target_id); // only include items under the parent foreach ($items as $item) { if (!$item->$parent_field) continue; $item_id = $this->top_level_id($items, $item->ID); if ($item_id == $target_id) { $filtered_items[] = $item; } } return parent::walk($filtered_items, $depth, $args); } // gets the top level ID for an item ID function top_level_id($items, $item_id) { $parent_field = $this->db_fields['parent']; $parents = array(); foreach ($items as $item) { if ($item->$parent_field) { $parents[$item->ID] = $item->$parent_field; } } // find the top level item while (array_key_exists($item_id, $parents)) { $item_id = $parents[$item_id]; } return $item_id; } }
Appel denavigation:
wp_nav_menu(array( 'theme_location' => 'main_menu', 'walker' => new Walker_SubNav_Menu(22), // with ID ));
I put together the following class for myself. It will find the top nav parent of the current page, or you can give it a target top nav ID in the walker constructor.
class Walker_SubNav_Menu extends Walker_Nav_Menu { var $target_id = false; function __construct($target_id = false) { $this->target_id = $target_id; } function walk($items, $depth) { $args = array_slice(func_get_args(), 2); $args = $args[0]; $parent_field = $this->db_fields['parent']; $target_id = $this->target_id; $filtered_items = array(); // if the parent is not set, set it based on the post if (!$target_id) { global $post; foreach ($items as $item) { if ($item->object_id == $post->ID) { $target_id = $item->ID; } } } // if there isn't a parent, do a regular menu if (!$target_id) return parent::walk($items, $depth, $args); // get the top nav item $target_id = $this->top_level_id($items, $target_id); // only include items under the parent foreach ($items as $item) { if (!$item->$parent_field) continue; $item_id = $this->top_level_id($items, $item->ID); if ($item_id == $target_id) { $filtered_items[] = $item; } } return parent::walk($filtered_items, $depth, $args); } // gets the top level ID for an item ID function top_level_id($items, $item_id) { $parent_field = $this->db_fields['parent']; $parents = array(); foreach ($items as $item) { if ($item->$parent_field) { $parents[$item->ID] = $item->$parent_field; } } // find the top level item while (array_key_exists($item_id, $parents)) { $item_id = $parents[$item_id]; } return $item_id; } }
Nav call:
wp_nav_menu(array( 'theme_location' => 'main_menu', 'walker' => new Walker_SubNav_Menu(22), // with ID ));
-
- 2011-03-15
@davidn @hakre Salut,j'ai une solution laide sans un analyseur HTML ou sans écraser display_element.
La classeclass Selective_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter return $output; if (empty($elements)) //nothing to walk return $output; $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if ( -1 == $max_depth ) { $empty_array = array(); foreach ( $elements as $e ) $this->display_element( $e, $empty_array, 1, 0, $args, $output ); return $output; } /* * need to display in hierarchical order * separate elements into two buckets: top level and children elements * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( 0 == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } /* * when none of the elements is top level * assume the first one must be root of the sub elements */ if ( empty($top_level_elements) ) { $first = array_slice( $elements, 0, 1 ); $root = $first[0]; $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( $root->$parent_field == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } } $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); //added by continent7 foreach ( $top_level_elements as $e ){ //changed by continent7 // descend only on current tree $descend_test = array_intersect( $current_element_markers, $e->classes ); if ( !empty( $descend_test ) ) $this->display_element( $e, $children_elements, 2, 0, $args, $output ); } /* * if we are displaying all levels, and remaining children_elements is not empty, * then we got orphans, which should be displayed regardless */ /* removed by continent7 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { $empty_array = array(); foreach ( $children_elements as $orphans ) foreach( $orphans as $op ) $this->display_element( $op, $empty_array, 1, 0, $args, $output ); } */ /*added by alpguneysel */ $pos = strpos($output, '<a'); $pos2 = strpos($output, 'a>'); $topper= substr($output, 0, $pos).substr($output, $pos2+2); $pos3 = strpos($topper, '>'); $lasst=substr($topper, $pos3+1); $submenu= substr($lasst, 0, -6); return $submenu; } }
@davidn @hakre Hi, i have an ugly solution without an HTML-Parser or overriding display_element.
class Selective_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter return $output; if (empty($elements)) //nothing to walk return $output; $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if ( -1 == $max_depth ) { $empty_array = array(); foreach ( $elements as $e ) $this->display_element( $e, $empty_array, 1, 0, $args, $output ); return $output; } /* * need to display in hierarchical order * separate elements into two buckets: top level and children elements * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( 0 == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } /* * when none of the elements is top level * assume the first one must be root of the sub elements */ if ( empty($top_level_elements) ) { $first = array_slice( $elements, 0, 1 ); $root = $first[0]; $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e) { if ( $root->$parent_field == $e->$parent_field ) $top_level_elements[] = $e; else $children_elements[ $e->$parent_field ][] = $e; } } $current_element_markers = array( 'current-menu-item', 'current-menu-parent', 'current-menu-ancestor' ); //added by continent7 foreach ( $top_level_elements as $e ){ //changed by continent7 // descend only on current tree $descend_test = array_intersect( $current_element_markers, $e->classes ); if ( !empty( $descend_test ) ) $this->display_element( $e, $children_elements, 2, 0, $args, $output ); } /* * if we are displaying all levels, and remaining children_elements is not empty, * then we got orphans, which should be displayed regardless */ /* removed by continent7 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { $empty_array = array(); foreach ( $children_elements as $orphans ) foreach( $orphans as $op ) $this->display_element( $op, $empty_array, 1, 0, $args, $output ); } */ /*added by alpguneysel */ $pos = strpos($output, '<a'); $pos2 = strpos($output, 'a>'); $topper= substr($output, 0, $pos).substr($output, $pos2+2); $pos3 = strpos($topper, '>'); $lasst=substr($topper, $pos3+1); $submenu= substr($lasst, 0, -6); return $submenu; } }
-
Après les avoirtousessayés,la solution d'Alp était la seule quifonctionnaitpourmoi.Cependant unproblème avec cela.Ilne montre que lesenfants depremierniveau,maisne montrepas lesenfants detroisième ou quatrièmeniveau.J'essaye depuis desjours de lefairefaire.Quelqu'un sait-ilmodifier sa solutionen tant quetelle?PS.Celane mepermettrapas d'ajouter des commentaires,alorsje dois lefaire comme réponse.After trying them all, Alp's solution was the only one that worked for me. However one problem with it. It on only show's the first level children, but does not show the third or fourth level children. I've been trying to for days to get it to do so. Anyone know how to modify his solution as such? PS. It won't let me add comments so need to do it as an answer.
- 0
- 2011-05-24
- cchiera
-
- 2011-02-08
La sortie dumenu denavigation comprend denombreuses classespour l'élément actuel,l'ancêtre de l'élément actuel,etc. Dans certaines situations,j'aipufaire ce que vous vouliezfaireen laissant latotalité de l'arborescence denavigationen sortie,puisen utilisant csspourparerseulement lesenfants de lapage actuelle,etc.
The nav menu output includes lots of classes for current item, current item ancestor, etc. In some situations, I have been able to do what you want to do by letting the entire nav tree output, and then using css to pare it down to only children of the current page, etc.
-
- 2011-04-20
J'ai créé un déambulateurmodifié qui devrait vous aider! Pasparfait - cela laisse quelques éléments vides,mais celafait l'affaire. Lamodificationestessentiellement cesbits $ current_branch. J'espère que ça aide quelqu'un!
La classeclass Kanec_Walker_Nav_Menu extends Walker { /** * @see Walker::$tree_type * @since 3.0.0 * @var string */ var $tree_type = array( 'post_type', 'taxonomy', 'custom' ); /** * @see Walker::$db_fields * @since 3.0.0 * @todo Decouple this. * @var array */ var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' ); /** * @see Walker::start_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. */ function start_lvl(&$output, $depth) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul class=\"sub-menu\">\n"; } /** * @see Walker::end_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. */ function end_lvl(&$output, $depth) { global $current_branch; if ($depth == 0) $current_branch = false; $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } /** * @see Walker::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param int $current_page Menu item ID. * @param object $args */ function start_el(&$output, $item, $depth, $args) { global $wp_query; global $current_branch; // Is this menu item in the current branch? if(in_array('current-menu-ancestor',$item->classes) || in_array('current-menu-parent',$item->classes) || in_array('current-menu-item',$item->classes)) { $current_branch = true; } if($current_branch && $depth > 0) { $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); $class_names = ' class="' . esc_attr( $class_names ) . '"'; $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : ''; $output .= $indent . '<li' . $id . $value . $class_names .'>'; $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; $item_output .= '</a>'; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } } /** * @see Walker::end_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Page data object. Not used. * @param int $depth Depth of page. Not Used. */ function end_el(&$output, $item, $depth) { global $current_branch; if($current_branch && $depth > 0) $output .= "</li>\n"; if($depth == 0) $current_branch = 0; }
}
I made a modified walker that should help! Not perfect - it leaves a few empty elements, but it does the trick. The modification is basically those $current_branch bits. Hope it helps someone!
class Kanec_Walker_Nav_Menu extends Walker { /** * @see Walker::$tree_type * @since 3.0.0 * @var string */ var $tree_type = array( 'post_type', 'taxonomy', 'custom' ); /** * @see Walker::$db_fields * @since 3.0.0 * @todo Decouple this. * @var array */ var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' ); /** * @see Walker::start_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. */ function start_lvl(&$output, $depth) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul class=\"sub-menu\">\n"; } /** * @see Walker::end_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. */ function end_lvl(&$output, $depth) { global $current_branch; if ($depth == 0) $current_branch = false; $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } /** * @see Walker::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param int $current_page Menu item ID. * @param object $args */ function start_el(&$output, $item, $depth, $args) { global $wp_query; global $current_branch; // Is this menu item in the current branch? if(in_array('current-menu-ancestor',$item->classes) || in_array('current-menu-parent',$item->classes) || in_array('current-menu-item',$item->classes)) { $current_branch = true; } if($current_branch && $depth > 0) { $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); $class_names = ' class="' . esc_attr( $class_names ) . '"'; $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : ''; $output .= $indent . '<li' . $id . $value . $class_names .'>'; $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; $item_output .= '</a>'; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } } /** * @see Walker::end_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Page data object. Not used. * @param int $depth Depth of page. Not Used. */ function end_el(&$output, $item, $depth) { global $current_branch; if($current_branch && $depth > 0) $output .= "</li>\n"; if($depth == 0) $current_branch = 0; }
}
-
- 2012-01-10
Consultez le code demonplugin ou utilisez-le à vosfins;)
Ceplugin ajoute un widget "Menu denavigation" amélioré.Il offre denombreuses options quipourraient être définiespourpersonnaliser la sortie dumenupersonnalisé via le widget.
Lesfonctionnalitésincluent:
- Hiérarchiepersonnalisée - "Uniquement les sous-éléments liés" ou "Uniquement strictement liés sous-éléments ".
- Profondeur de départet niveaumaximum à afficher + écranplat
- Affichertous les éléments demenuen commençantpar celui sélectionné.
- Afficher uniquement le chemin direct vers l'élément actuel ou uniquement lesenfants de
élément sélectionné (optionpourinclure l'élémentparent). - Classepersonnaliséepour unbloc de widget.
- Etpresquetous lesparamètres de lafonction wp_nav_menu.
Check out the code in my plugin or use it for your purpose ;)
This plugin adds enhanced "Navigation Menu" widget. It offers many options which could be set to customize the output of the custom menu through the widget.
Features include:
- Custom hierarchy - "Only related sub-items" or "Only strictly related sub-items".
- Starting depth and maximum level to display + flat display.
- Display all menu items starting with the selected one.
- Display only direct path to current element or only children of
selected item (option to include the parent item). - Custom class for a widget block.
- And almost all the parameters for the wp_nav_menu function.
J'ai unmenu défini dans WP Admin qui ressemble à ceci:
Je souhaitepouvoir affichertous les liensenfants dans labarre latérale chaquefois queje suis sur unepageparent. Parexemple,si l'utilisateurest surmapage "Àpropos denous",je souhaite qu'une liste des 4 liens surlignésen vert apparaisse dans labarre latérale.
J'ai regardé la documentation de wp_nav_menu () et ellene semblepasen avoirmanièreintégrée de spécifier unnœudparticulier d'unmenu donné à utiliser commepoint de départ lors de lagénération des liens.
J'ai créé une solutionpour une situation similaire qui reposait sur les relations crééespar leparent de lapage,maisj'en cherche une qui utilise spécifiquement le système demenus. Toute aide serait appréciée.