How to create a static WordPress navigation menu

I wanted to create a static navigation menu creating a combination of both static pages (for home, about, contact, etc) and categories (for tutorials and portfolio) for a WordPress 2.9.2 website.
This meant that the regular way of automatic listing (wp_list functions) was not going to do it for me, as this would automatically expand when a new category or page was added. As none of the answers I found covered the whole of my question, I’ll post it here for your convenience!

It’s not difficult. All you have to do is add some pieces of code to header.php. For this example, I’m assuming a website with four pages: Home, Services, About and Contact, and two categories: Portfolio and Tutorials:

1. Add the php code below to the -head- part of the header.php file:

     
<?php 
 if ( is_page('Home') ) { $current = 'menu_one'; } 
  elseif ( is_page('Services') ) { $current = 'menu_two'; } 
  elseif ( is_page('Portfolio') ) { $current = 'menu_three'; } 
  elseif ( is_page('Tutorials') ) { $current = 'menu_four'; } 
  elseif ( is_page('About') ) { $current = 'menu_five'; } 
  elseif ( is_page('Contact') ) { $current = 'menu_six'; } 
?>

2. Add the html code below to the -body- part of header.php:

<div id="navbar">
    <ul id="nav" class="clearfloat">
        <li id="menu_one"><a href="index.php?page_id=15">Home</a></li>
        <li id="menu_two"><a href="index.php?page_id=7">Services</a></li>
        <li id="menu_three"><a href="/yourtheme/archives/category/Portfolio">Portfolio</a></li>
        <li id="menu_four"><a href="/yourtheme/archives/category/tutorials">Tutorials</a></li>
        <li id="menu_five"><a href="index.php?page_id=9">About</a></li>
        <li id="menu_six"><a href="index.php?page_id=13">Contact</a></li>
    </ul>
</div>
3. The paths are key here, and depend on the permalink structure you’re using. In this case, I used the default setting.

4. All you have to do now is fill in the menu-names you want to use yourself, and change /yourtheme/ into the name of the theme you’re using.
Initially, I used index.php?cat=”cat_ID_number” instead of archives/category/portfolio. But for some reason, the posts in that category would then not show up, instead I got a 404. The posts were found when clicking the specific category in the sidebar. I’m not sure what the index.php?cat= function would do then, but the folder path works very well!

This post was last modified on 27/01/2020 14:46

Boris Hoekmeijer

View Comments

Share
Published by
Boris Hoekmeijer

Recent Posts

Agribusiness Service

Website en logo ontwerp voor Kookstudio Aalsmeer - voor uw kookclub, kookfeest of bedrijfsuitje in…

4 months ago

CardioThoracaal Chirurgie Zorgpad

Website en logo ontwerp voor Kookstudio Aalsmeer - voor uw kookclub, kookfeest of bedrijfsuitje in…

4 months ago

7huijzen Food Quality & Innovation Management

Website en logo ontwerp voor Kookstudio Aalsmeer - voor uw kookclub, kookfeest of bedrijfsuitje in…

6 months ago

Prime Housing

Website en logo ontwerp voor Kookstudio Aalsmeer - voor uw kookclub, kookfeest of bedrijfsuitje in…

6 months ago

Cor de Kroon

Website en logo ontwerp voor Kookstudio Aalsmeer - voor uw kookclub, kookfeest of bedrijfsuitje in…

8 months ago

Hoe leeg je de cache van je browser?

Building your WordPress website efficiently using the 10 tips I documented after years of experience.…

1 year ago