$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>menus - Use wp_nav_menu to display ALL pages|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

menus - Use wp_nav_menu to display ALL pages

matteradmin9PV0评论

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>

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>
Share Improve this question asked May 20, 2014 at 8:38 Sam SkirrowSam Skirrow 1072 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/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/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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far