WordPress.org

Ready to get started?Download WordPress

Forums

How to loop through PAGES in custom Navigation Menu (4 posts)

  1. hyoon01
    Member
    Posted 10 months ago #

    So for my website, I am making it so that the content of each page in the current navigation menu would be displayed on the main home page.

    So main question is, how would I write the query so that it looks up all the pages which are in the navigation menu?

    Would I need to find out the page_id of each page in the menu and then pass that information through query? If so, how would I find the page_id of the nav_menu?

  2. bcworkz
    Member
    Posted 10 months ago #

    The nav menu only stores the actual URL, no other pertinent information. After all, a menu link could even be offsite if you were so inclined. So there is not one single way to get more information about a menu item, it depends on the nature of the URL.

    If all the links are page slugs, you could pull the URLs out of the DB and extract the slug. Then use the slug to retrieve the page. Perhaps easier is to setup your home page template with a series of iframes for which the menu URL is inserted directly into the iframe src attribute.

    To get all the menu URLs, query for all the menu items, which are special post type 'nav_menu_item'. The URLs are in postmeta for each menu item under the key '_menu_item_url'.

  3. hyoon01
    Member
    Posted 10 months ago #

    k thanks a lot!!

  4. ubaidullahbutt
    Member
    Posted 9 months ago #

    It may help

    query_posts(array('showposts' => <number_of_pages_to_show>, 'post_parent' => <ID of the parent page>, 'post_type' => 'page'));
    
    while (have_posts()) { the_post();
        /* Do whatever you want to do for every page... */
    }
    
    wp_reset_query();  // Restore global post data

Reply

You must log in to post.

About this Topic