1

I am currently building a wordpress theme. For the menu, I just want to display all the pages that are created in the order that they are created in (i.e. I don't want users to have to go into the 'menu' section of the site and create their own).

I tried using wp_page_menu and this worked HOWEVER I need to add a walker class to expand the functionality, which you can't do with this function. So I need a way to display all my pages with using wp_nav_menu as my code - is there a way to do this?

Here is my code currently:

<nav id="nav">
    <?php wp_nav_menu( array( 'walker' => new Clapton_Nav_Walker ) ); ?>
</nav>

1 Answer 1

3

You could move away from wp_nav_menu() completely and instead use wp_list_pages().

See the codex for more information, but I believe this may be what you are looking for.

http://codex.wordpress.org/Function_Reference/wp_list_pages

I do understand that this function outputs the pages. The point I was trying to make though is that you can use this in conjunction with CSS to get it looking like a menu. I made an example page that includes this code:

    <?php
/*
* Template Name: Testing
*/
    ?>
    <link rel="stylesheet" type="text/css" href="http://nickyoungweb.com/zip/wp-content/themes/THS2012/style.css" />
    <nav id="nav">
         <?php
            wp_list_pages( array(
                'title_li' => ''
            ));
         ?>
       <br style="clear: both; ">
    </nav>

I have it linked to a stylesheet that contains this code:

    /**** WP LIST PAGES NAV *****/
    nav {  }
    nav li { list-style-type: none; float: left; }
    nav li a { width: 50px; height: 30px; background: #000; color: #fff; padding: 10px; margin: 2px; }
    nav li a:hover { background: #f00; color: #000; }
    nav ul li { display: none; }

It is a very basic example of how you could make it work with this function.

Hopefully this helps clear up any confusion I might have caused you and also gives you an idea of how it CAN be done with this function.

4
  • How this will be beneficial? It will just list the pages not a menu. May 20, 2014 at 9:25
  • Yes it will list all of the pages as the OP wishes to do. There is also an argument for a walker and it can be styled to look like a navigation menu.
    – Nick Young
    May 20, 2014 at 9:27
  • Thanks for this suggestions, but @Chittaranjan is correct, it only outputs the pages, it doesn't act like a menu May 20, 2014 at 10:16
  • Updated my answer to show a better example of how this could actually work. Link included as a basic example of a menu created using wp_list_pages(). Hope it helps.
    – Nick Young
    May 22, 2014 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.