September 23, 2004
Creating a Horizontal Navigation Bar
The default Movable Type layouts don't give you a lot of choice in terms of navigation. Clicking on the top bar with the title of the weblog will take you back to the main page of the weblog. Every other nav element is in the sidebar. You can however, pretty easily add a horizontal nav bar, with links to important-to-first-timers, or frequently used areas of your site, such as archives, about, or contact links.
Adding horizontal nav bar requires adding a few lines of code right underneath the banner section in your index and archive templates and adding a few new elements to your style sheet. Once you've created your navigation code, the most efficient way to add the code to the index and archive templates is with the use of an include, either a PHP or MT Include.
1. Decide what you want to have in your top navigation.
If you want links to an about page or a contact page, you need to create those pages (see Creating an About Page). By default every MT blog comes with a master list of all of your entries at www.yourblog.com/archives.html. You can link to this for your archives, or you can create a new index template with the archives organized the way you want.
2. Create the index template navigation code.
The following is one example of the most basic horizontal navigation, using text and css. Start by editing your Main Index template. After the ending div tag of the banner code section, add a navigation div ID followed by links to the sections of your blog to which the navigation will point.
Save the template.
3. Add navigation elements to the Stylesheet.
Add #nav style information at the bottom of your stylesheet. Adjust for padding, margin, font, background color, border, and link style. For example,
Save template and rebuild the stylesheet and Main Index templates.
4. Adjust the code if you want some elements on the left and some on the right of your nav bar.
To split the navigation into left and right sections create 2 additional classes in your stylesheet and use the span html tag to incorporate those classes on your index template.
This is an example of the original nav code explained above now split into two separate classes:
These classes can be added to your stylesheet, below the #nav ID element.
5. Create an include file.
You can add a nav bar without using includes by just adding the nav html to each of your index and archive templates, anywhere your banner appears. However, it is much easier to create a separate include file. That way when you change one element of your navigation, the changes are immediately reflected on all of your template pages.
To create an include file, follow the instructions in the tutorial Using PHP and MT Includes. If your site is not set up for php, use an MT Include. The only difference is that you will need to rebuild your site when you make a change to the navigation template, in order for the change to be reflected on the site.
It always helps to view your weblog in many different browsers to make sure everything looks as you expect it to. One odd behavior I encountered adding a nav bar to LMT is that IE Windows and Firefox put a border around the banner, which is a clickable image. This border interfered with the nav bar. To get rid of this problem I added a #banner img element like so:
Another odd behavior I encountered with Firefox was the right side nav text disappeared off of the nav bar, even though the page validated, as well as the CSS. I found ordering the <span class="navright"> before the <span class="navleft"> in the index template corrected this problem.
Has this tutorial been helpful? Please consider linking to Learning Movable Type at http://learningmovabletype.com/ . Thanks!
If you would like to send a trackback
please use the following URL: http://learningmovabletype.com/cgi-bin/mt32/mt-tb.cgi/346