Skip to main content

Ivan Teoh

Something personal yet public

WordPress List Pages

On previous post, I edited the header.php for including horizontal menu on listing main pages on this site. The code is as below:

27-header-before.php (Source)

<div id="navmenu">
<ul>
    <li><a href="<?php echo get_settings('home'); ?>">Home</a></li>
    <li><a href="blog">Blog</a></li>
    <li><a href="Gallery">Gallery</a></li>
    <li><a href="about">About</a></li>
</ul>
</div>

Now, I want it to be dynamically list all the main pages on this site in horizontal menu. The way to do is using wp_list_pages(); template tag. With this, I don't have to manual edit the code if new page is added. Below are the new replacement code in header.php.

27-header-after.php (Source)

<div id="navmenu">
<ul>
    <?php wp_list_pages('depth=1&sort_column=menu_order&title_li='); ?>
</ul>
</div>

Comments

Comments powered by Disqus