Skip to navigation

Site Navigation

Effective site navigation helps users find their way around a site. It means people are more likely to find what they're looking for on your site, and will spend more time browsing on it. Most site navigation features are generated by the Pyplate API.

The Navigation Bar

The navigation bar is the menu along the top of the page. It can be created in two different ways (whichever way it is created, CSS styling is used to make the list appear horizontal). It can be generated by calling get_navbar from pyplate.py, a function which generates an HTML list of links to all the top level categories. For example, if a site has categories named 'a', 'b', and a subcategory named 'c' contained in 'a', then the navigation bar will contain links to the home directory, 'a' and 'b'. 'C' won't appear in this menu because it's a subdirectory. The generated code would look like this:

<div class="navbar"> <ul class="navmenu"> <li><a href="/">Home</a></li> <li><a href="/a/">A</a></li> <li><a href="/b/">B</a></li> </ul> </div>

Users who want a customized navigation bar can write the HTML code by hand in the Site Settings page in the admin area. This is useful when you want to include extra links in your navigation bar. This site uses a hand written navigation bar in order to include the link to the forum. The forum isn't a category in the Pyplate database, so it wouldn't appear in code generated by get_navbar.

In the HTML layouts in layouts.py, each page layout has a {navbar} field, which is substituded for another string when format() is called in get_layout. If you want to use a hand written navigation bar, the navbar field should be set by using getFile to access the navbar file in the template directory:

navbar=pyplate.getFile(pyplate.getCMSRoot() + "/template/navbar.html"),

If you'd rather use a navigation bar that just contains a list of links to top-level categories, then the navbar feld should be set like this:

navbar=pyplate.get_navbar(database),

The Sidebar

The sidebar contains the main site navigation menu, which lists all categories and posts. The sidebar is generated by a call to pyplate.get_sidebar. The menu is generated by calling pyplate.get_menu, a function that prints categroy names wrapped in h2 tags, and prints the titles of posts in each category as an item in an unordered list. Categories displayed in the order specified in the position field in each category record.

In the default theme, the sidebar just contains the site menu. If you look at the right hand column on this site, you can see that there are several other panels in the sidebar. The HTML for each file is stored in a file in the template durectory. The sidebar layout in the theme's layout.py needs to be modified to include extra panels. Pyplate.getFile is used in getLayout to fill in the sidebar panels.

Generating the HTML code for the sidebar can be quite CPU intensive because Pyplate needs to execute quite a lot of code to generate the navigation menu. Instead of generating the sidebar every time a page is generated, the sidebar is cached in the template directory. The sidebar file is deleted when the cache is cleared. If the sidebar file can't be found when Pyplate generates a page, it will be generated and cached for future use.

The sidebar file in the template folder should not be edited manually as it will be deleted when the cache is cleared, and modifications will be lost.

Category Menu

Pyplate.get_category_menu is a lot like the pyplate.get_menu function that's used to generate the site menu. The main difference is that pyplate.get_category_menu only displays the contents of the current category and its subcategories. This makes it easy for people to see what other pages are in the same category. When people finish reading an article on a web site, they often look around the bottom of the article to see if there's anything else to read on the site, so it's common to use this feature underneath the main content on a page.

Breadcrumbs

Breadcrumbs are a list of links, usually near the top of a page, that make it easier for users to see where the page they are viewing fits into the hierarchy of your site's categories. Breadcrumbs also make it easy for users to get to higher level categories. The HTML code for breadcrumbs is generated by pyplate.get_breadcrumbs.

Share this page:

Follow me