WordPress as a CMS… Advanced Navigation

Wordpress
Creative Commons License photo credit: drustar

One of the things that is starting to happen at OLT is that we are creating an increasing number of WordPress based websites. Using WordPress as a content management system is not a new idea at all, there are a ton of examples out there of WordPress blogs out there that have been turned into sites. There is however, a dearth of information out there on how to do it (there are some out there… including some in amazing detail from Alan Levine).

One of the things that I couldn’t find was a stable way to create a second level navigation that stays constant for every top level section. The problem with most of the solutions on the forums and sites around is that as soon as you drill down to the third level of navigation the second level disappears. As you can see at aboriginal.ubc.ca I was able to come up with a way to keep the navigation constant. Here is the loop that I had to create:

<?php
$secondAncestor = count($post->ancestors) -1; //figure out what level of navigation we are on, subtract one because we don't want to consider the top-level
if($post->post_parent!=0) //if the page is not a top-level category
{
echo '<h2 class="widgettitle">In this section:</h2><li class="sidebarlist">';
//the following lists children of second level ancestor of the current page.
wp_list_pages("title_li=&child_of=".$post->ancestors[$secondAncestor]."&    sort_column=menu_order&echo=1");
echo '</li>';
}
else //if the page is a top-level category
{
//listing only the child pages of the current section
$children= wp_list_pages("title_li=&child_of=".$post->ID."&  sort_column=menu_order&echo=0");
if($children) //this will stop it from displaying a section heading if there are   no elements in the section (for example on the home page)
{
echo '<h2 class="widgettitle">In this section:</h2><li>';
echo $children;

echo '</li>';

}
}
?>


This is the first time I’ve blogged code, I’m not even sure if it is readable… but here’s hoping. Basically I figure out what level of navigation the user is on and then list the pages of the current page’s ancestor… that many levels up (subtracting one for the top level navigation.

I am currently doing a lot of work on using WordPress as a content management system including coming up with plugins and modifications for using WordPress MU as a multi-site manager used purely for websites and not for blogs. Will blog it all once everything is stable and working.

Zemanta Pixie

Edugluing things together

so here is a mapping of my plan for a UBC content management strategy. It is designed to overcome two obstacles:

1) Content changes, therefore the content stored in repositories has to change and be updated when the source is updated. This is overcome by using a wiki (this has been Novak’s vision of content management for a while) that produces RSS feeds along with an aggregator like Feed WordPress that updates the repository when a feed gets updated (that feature is still buggy at the moment, but I will get to fixing that ASAP).

2) The second obstacle is the fact that RSS and JavaScript are not easily searchable (a must for a content repository or even an end user site). Republishing is a must until we find an easy way to index and search RSS and JSON.

So here is what it looks like (click on it for larger view):