Editing Menus In Your Theme

Pretty much every wordpress theme that you find will have some sort of navigation menu of top-level pages. After all, how else would users be able to easily navigate your website? Here are a few methods to customize those menus in your theme.

1. Displaying a list of pages

This one is fairly straightforward. While there are a bevy of options to choose from, the wp_list_pages function is basically a way to display all of the pages on your site in a list.


With the example above, I created a container with the name of “navigation” to put the menu in. I then created an unordered list, and inside used the wordpress “list_pages” function to call the pages that are on my site. The “title_li=” means that there is no title displayed for the list (the default is the word “pages”). An ampersand adds the next option, “depth=1”, which tells it to only grab the top level pages to display. So if I have a page called “Company”, with subpages “About”, “Contact”, etc, only the “Company” page will display.

2. Adding the Home Page to your Menu

Next we want to display the page that we have set as our index on the menu. This is useful if the index is a post page, where it wouldn’t otherwise have its own editable page in the dashboard, or if we are choosing particular pages to display and want it to show as “yoursite.com” as opposed to “yoursite.com/home/”, or whatever page you have selected.


That now adds a list item that is a link to the homepage of your site, and displays it as “Home”, which can be edited at any time.

3. Making a Custom Menu

Our last example will be using custom menus, like the Amoeba framework has built in. These would show up something like this:


Then you’d add this to your functions.php file:

 'Custom Menu',
	  		  'custom-menu2' => 'Custom Menu 2',
	  		)
	  	);
	}
?>

The function is set up as an array, so that you can easily add more in, naming them whatever you choose. When you go to the Appearance tab in your dashboard, you’ll see the Menus link. Clicking on that will take you to a page where you can set up your menu. You can select specific pages, categories, even external links, and add them to your menu in any order that you please. Then, wherever that menu is called in your theme, the links will show up! This makes a powerful tool when you have specific requirements for the navigation of your website.

That’s it!

That’s it for now, I hope that the examples above are of help. There are plenty of ways to create and style customized menus, and I’m sure some of you have your own. Feel free to ask questions about any of the examples, or share ideas for navigation of your own in the comments.


Posted

in

,

REPUBLISHING TERMS

You may republish this article online or in print under our Creative Commons license. You may not edit or shorten the text, you must attribute the article to david wolfpaw and you must include the author’s name in your republication.

If you have any questions, please email david@david.garden

License

Creative Commons License AttributionCreative Commons Attribution
Editing Menus In Your Theme