How to create editable menu with parent and child in wordpress?

admin2025-06-02  3

I have created a admin menu in wordpress, and it is a main menu, I do have one parent page and also associated with that there are some child pages. I want to get the images of that child pages needs to be displayed in the menu also, links to the child pages like button. How can i do this in wordpress? wp_get_nav_menu_items function.

structure is below.

Parent-A
    some description of parent-A page
    child-A->child-A page feature Image and two buttons
    child-B->child-B page feature Image and two buttons
    child-C->child-C page feature Image and two buttons
Parent-B
    some description of parent-B page
    child-D -> child-D page feature Image and two buttons
    child-E -> child-E page feature Image and two buttons
    child-F -> child-F page feature Image and two buttons

I have created a admin menu in wordpress, and it is a main menu, I do have one parent page and also associated with that there are some child pages. I want to get the images of that child pages needs to be displayed in the menu also, links to the child pages like button. How can i do this in wordpress? wp_get_nav_menu_items function.

structure is below.

Parent-A
    some description of parent-A page
    child-A->child-A page feature Image and two buttons
    child-B->child-B page feature Image and two buttons
    child-C->child-C page feature Image and two buttons
Parent-B
    some description of parent-B page
    child-D -> child-D page feature Image and two buttons
    child-E -> child-E page feature Image and two buttons
    child-F -> child-F page feature Image and two buttons
Share Improve this question edited Feb 21, 2019 at 17:55 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Feb 21, 2019 at 15:06 NaveenNaveen 1992 gold badges4 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1

WordPress has some functions to help work with lists of objects. These are especially helpful when working with the nav menu objects or the query object.

wp_filter_object_list() takes an array of objects and filters them by a given set of criteria. You get a result that only contains objects that match your criteria.

Once you get a list of the menu items you'd like to loop through, you can check conditions to output different things. For example, what's the depth? What is the parent post id? etc. After that, grab the relevant information from the associated post id.

I hope that helps.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748879757a314486.html

最新回复(0)