Support » Themes and Templates » Combined navigation (pages and categories)

  • I’d like to use WP as a CMS for a site. I’ve played around with it for a couple of days now and it seems to be perfect. The only confusion is creating the navigation. I’d like to have pages and categories in the navigation, mixed. Most of the pages would be static (with sub pages), but there would be some “bloggish” content as well.

    The other problem is that I’d like to have the 1st level navigation horizontally on top and the next levels vertically. Once I click a second level item it’d open up the third level, etc. It’s a common practice, but see this image for clarity:

    I already created a hack that loaded the page structure in to an array, which I then unfolded using some PHP scripting. I suppose I could hack in the categories as well, but it all ends up being a bit… complicated 🙂

    Would you have any other ideas on how to get this to work? Would it be ok to create pages for the “bloggish” content and then assign custom templates to them (listing the articles in the category)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • This might be of some interest to you:

    To do what you want, I believe, for your menus:

    And instead of relying upon the template tags for your navigation, since you really want control over them, consider using specific links to these things by hand coding them. That’s what I did with mine.

    Thanks for your replies. So it seems I’ll have to go with some custom stuff. I’d like to make it (at least partly) automatic, so maybe I’ll just try to improve the navigation function I already built. I suppose it’d be easy to build it as a plugin. If I manage to build it elegantly then I could give back something to the WP community 🙂 Here’s what I have in mind (and crudely done, but the code is at work):

    EDIT: Moved to external file for better readability:

    One would then build the pagetree in the header <? $pagetree=$buildPageTree(); ?> and write the first level (horizontal) navigation where they’d like it: <? writeFirstNavilevel($pagetree); ?>. I’ve also got a recursive function for building up the left level navigation with automatic indentation.

    This still leaves open the issue of loading up categories, but I can do that by manually inserting them to the $pagetree after it has been generated.

    I worked on it a bit. Still missing stuff, but you can now test it if you wish:

    This plugin gives you two functions: buildPagetree() and writeFirstLevelNavi(). The following code will give you your pages in a hierarcical array:

    ‘<pre><?php print_r(buildPagetree()); ></pre>’

    The first plugin is not that useful because the pagetree is still missing the “active” property to give you the option for setting your links as active and providing folding levels, etc. but I have it working on the first version (which is at the office).

    Another problem with the approach could be problems with performance… This creates a bunch of extra queries on your database. It could be optimized to only fetch subcategories of the active level… And with a cache in place the overhead is less a problem.

    Let me know if you find this useful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Combined navigation (pages and categories)’ is closed to new replies.