Home and the rest of main menu on a WordPress based web site
Posted by Leonid Mamchenkov on August 3, 2007
Now that we established that WordPress is not just a blogging engine, but a complete platform, which can be used for building all sorts of web sites, it is time to look at some issues which arise along the way. Today, I’ll show one of the ways to go about creating web site’s main menu.
For most traditional web sites, WordPress pages provide all required navigational functionality. Simply create pages for main menu items, like “About Us”, “Contact Us”, “Services”, “Company Profile”, etc. Those pages which need sub-sections, can have sub-pages (via “Page Parent” selection box).
Pages can be ordered in a number of ways with parameters in the theme files, and there is even some control in the administration interface. Take a look at arguments for wp_list_pages() function and “Page Order” selection box in the administration interface.
The biggest issue that I came across, is the one with Home link. There is usually a company or web site logo, which is linked to the front page of the site, but often also a main menu item makes sense. People expect a “Home” or “Main” or “Front page” link in the main menu.
OK, no problem. We create a separate page, call it “Home” and arrange the ordering for it to be the first. Also, in the Options->Reading we select “Front page displays a static page” and select our “Home” page. Now our menu works just fine.
Except for the tiny little detail – “Home” link in the menu doesn’t point to the web site’s front page, but to an address of the page. With fancy URLs it might not be that noticeable (/home), but with regular links, it doesn’t look right (/page_id=2). Updated: this seems to be not true for the newer version of WordPress, which use blog’s home automatically. Thanks to Rich Schmidt for pointing this out.
Also, our front page looks a little bit strange, with the title “Home” instead of something more traditional like “Welcome to our new web site!”. We could, of course, take care of this by using a different template for the front page, but why bother, especially when we can solve both issues at the same time and do it easily to.
A quick and simple solution is to separate the “Home” link from the rest of the pages menu. So, instead of:
We’ll have something like this:
Here, 2 is the ID of our “Home” page, which we want to exclude from the main menu (check Codex for more about wp_list_pages() ). Otherwise we’ll have two entries in there and it will be confusing.
Update: Thanks to Adam and Greg (see comments) for a better way to do the above:
So, now, not only our “Home” link in the main menu points to something sensible, but we also get to choose our front page title separately from the menu item.
If your web site should be more flexible with page titles and menu items, but you still want to keep the administration simple (because, most probably, very non-technical people will handle the content), you can use Links instead. We’ll see how to do it next time.
This entry was posted on August 3, 2007 at 8:23 am and is filed under Menu, Pages, WordPress. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.