Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13793 closed enhancement (wontfix)

Missing child_of parameter to wp_get_nav_menu_items

Reported by: dreadlox's profile DreadLox Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

Hello,

To get a portion of a menu we need a child_of parameter to wp_get_nav_menu_items function like wp_list_pages has.

As the $args passed to wp_get_nav_menu_items are passed to get_post, I tried to gibe it a post_parent argument but no success.

As the new menu system is an enhancement over menus based on pages, it is a bug as it is a regression over the old way to display menus.

Regards

Attachments (1)

patch_menu_child_of.patch (2.1 KB) - added by DreadLox 14 years ago.
Patch to add a child_of parameter to wp_name_menu

Download all attachments as: .zip

Change History (14)

#1 @DreadLox
14 years ago

  • Version set to 3.0

As I really needed it. I have implemented it. The patch is attached.

@DreadLox
14 years ago

Patch to add a child_of parameter to wp_name_menu

#2 @westi
14 years ago

  • Keywords has-patch added
  • Milestone changed from 3.0 to Future Release
  • Priority changed from high to normal
  • Severity changed from major to normal
  • Type changed from defect (bug) to enhancement

The menu implementation in WordPress 3.0 is intentionally a first step into the world of menus.

As such it won't support every feature you might want.

If you are just trying to display the submenu of a section of the page hierarchy you would do much better to carry on using wp_list_pages for that.

Moving out of the 3.0 milestone and marking as an enhancement request.

#3 @filosofo
14 years ago

This sounds niche. What are some applications for its use?

#4 follow-up: @DreadLox
14 years ago

What is wrong committing it for Wordpress 3.0 release? It is just a few lines of code and it uses the child_of parameter the same way wp_list_pages does, without doing additional SQL queries.

Sorry, but the fact that "the menu implementation is intentionally a first step into the world of menus" is not a good reason to provide less to wordpress devs/users whereas the code is ready to provide more.

Isn't the new menu system supposed to be an improvement over the old way of using pages hierarchy? If so, it shouldn't bring any regression compared to the old system, and should _at least_ include the same set of functionality.

If something is wrong with my code, tell me, I'll understand it.

Also what my patch provides can't be achieved using a plugin. Maybe you could just add an action/filter, so such a functionality could be implemented using a plugin.

#5 in reply to: ↑ 4 ; follow-up: @filosofo
14 years ago

Replying to DreadLox:

Also what my patch provides can't be achieved using a plugin. Maybe you could just add an action/filter, so such a functionality could be implemented using a plugin.

Actually you can, a number of ways. I would either call wp_get_nav_menu_items directly or extend the Walker_Nav_Menu class.

What is the use-case for this feature?

#6 in reply to: ↑ 5 ; follow-up: @DreadLox
14 years ago

Replying to filosofo:

Replying to DreadLox:

Also what my patch provides can't be achieved using a plugin. Maybe you could just add an action/filter, so such a functionality could be implemented using a plugin.

Actually you can, a number of ways. I would either call wp_get_nav_menu_items directly or extend the Walker_Nav_Menu class.

When using wp_get_nav_menu_items directly I then miss all the wordpress great code that generates the html menu with classes etc... Extending Walker_Nav_Menu class is rather complicated.

What is the use-case for this feature?

I have some websites where the first level of the menu get displayed as the website "top bar" menu. When one enters one of those, a submenu of that level get displayed in the sidebar. (plz excuse my bad english)

So, I first get the current page's top parent ID and then:
if($TopParentId) wp_nav_menu( array('child_of'=>$TopParentId) );

Again if you really do not want such a specific feature just add a filter to menu_items:

$menu_items = apply_filters( 'wp_nav_menu_items', $menu_items, $args );

Thanks.

#7 @DreadLox
14 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

After a little thinking, adding a filter definitely does the trick and keeps wordpress light and powerful.

I close that bug as I have opened an other one: http://core.trac.wordpress.org/ticket/13858

#8 @nacin
14 years ago

  • Milestone Future Release deleted

#9 @AdmireNL
14 years ago

Does anyone have a complete example for how to show a submenu in Wordpress 3.0?
I would like to show only the submenu of a parent in the sidebar, with 'wp_nav_menu'

For instance:

mainMenu:
HOME | SERVICE | CONTACT

I woulde like to have a submenu with

<h2>SERVICE</h2>

  • Service 1
  • - Service 1 a
  • - Service 1 b
  • Service 2
  • Service 3

Help is much appreciated since I can't find a solution and searching for days.

#10 in reply to: ↑ 6 @AdmireNL
14 years ago

Replying to DreadLox:

Replying to filosofo:

Replying to DreadLox:

Also what my patch provides can't be achieved using a plugin. Maybe you could just add an action/filter, so such a functionality could be implemented using a plugin.

Actually you can, a number of ways. I would either call wp_get_nav_menu_items directly or extend the Walker_Nav_Menu class.

When using wp_get_nav_menu_items directly I then miss all the wordpress great code that generates the html menu with classes etc... Extending Walker_Nav_Menu class is rather complicated.

What is the use-case for this feature?

I have some websites where the first level of the menu get displayed as the website "top bar" menu. When one enters one of those, a submenu of that level get displayed in the sidebar. (plz excuse my bad english)

So, I first get the current page's top parent ID and then:
if($TopParentId) wp_nav_menu( array('child_of'=>$TopParentId) );

Again if you really do not want such a specific feature just add a filter to menu_items:

$menu_items = apply_filters( 'wp_nav_menu_items', $menu_items, $args );

Thanks.

Hi Dreadlox, your comment seems to get very close to what I like to achieve, but I don't know how to get the 'TopParentId'

if($TopParentId) wp_nav_menu( array('child_of'=>$TopParentId)  );

Thanks a lot in advance!
Arnoud

#11 @adiaz
14 years ago

Is there any posibility that this patch is included in a future release?
It is really needed!

#12 @Gecka
13 years ago

  • Keywords needs-patch needs-refresh reporter-feedback dev-feedback 2nd-opinion close needs-testing ui-feedback ux-feedback needs-ui needs-unit-tests needs-docs rtl-feedback needs-codex added

It seems that only patches from the wordpress maintainers are allowed here. So many submitted patches, so many hour of work to have them ignored or, worst, rewritten and committed under an other name.

Wordpress development or how to make contributors run away....

#13 @SergeyBiryukov
13 years ago

  • Keywords needs-patch needs-refresh reporter-feedback dev-feedback 2nd-opinion close needs-testing ui-feedback ux-feedback needs-ui needs-unit-tests needs-docs rtl-feedback needs-codex removed
Note: See TracTickets for help on using tickets.