WordPress Themes: Menu instead of Pagelist

So you found this nice theme that really works well for your blog? That’s great. But sometimes Themes are not updated by their authors to use the latest features in WordPress. In my Case, i am using Simple Green by Flavius Matis, but it hasn’t been modified for quite some time. The Plugin doesn’t yet feature WordPress Menus, which were introduced recently.

Since there are many reasons to choose a menu over a pagelist, i decided to add them on my own. Although i am describing the steps for Simple Green, you should not have any troubles to apply them to any other theme as well.

Locate the right place

Your theme will probably have a list of pages somewhere (most of the time in a file called header.php). If you can’t locate a similar line in your theme, there may be two possibilities: it may either not have a list of pages or it displays them as a sidebar widget. It it’s a sidebar widget, you can simply change it to a menu-widget on the widgets administration page.

In our example, it looks something like this:

<div id="main_menu">
  <ul>
    <li><a href="<?php echo get_option('home'); ?>">home</a></li>
    <?php wp_list_pages('title_li='); ?>
  </ul>
</div>

The Change

Note the wp_list_pages() in line 34. We’ll replace the lines 32-36 with the newer call to wp_nav_menu(). Please note, that the output and parameters of both calls are not identical. For my theme, this yielded another div-container which i didn’t want. I just added the code ‘container=’ to disable the extra div.

<div id="main_menu">
  <?php wp_nav_menu('container='); ?>
</div>

The default behaviour is to simply list all the pages as a menu. If you haven’t yet configured your own menu, this shouldn’t look much different than before. In my case, the “Home” link was gone, and that’s it. Now you may use the Menu-Editor in the Appearance-Settings to add pages, categories and other links to your menu!

7a8
>       <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/amenthes.css" type="text/css" media="screen,projection" />
31,34c32
<                       <ul>
<                               <li><a href="<?php echo get_option('home'); ?>">home</a></li>
<                               <?php wp_list_pages('title_li=' ); ?>
<                       </ul>
---
>                       <?php wp_nav_menu('container='); ?>

Comments are closed. Please feel free to Contact me directly!


Author

Claudius Coenen is a tech-enthusiast. He's writing on all kinds of topics, including programming, technology, gadgets and media.

This site features his occasional articles, findings, documentations.

Categories

Connect

RSS Recent Bookmarks

Legal