Topic: Menu with (text) sub-headings.

Hi

I've have a site with a typical left hand menu in it. The menu has sub-headings. I've just successfully completed my first wolf template and I used the standard code for link generation from the menu cookbook.

My Question is this: How do I alter the menu php code so that when I create pages, they go into the correct catergory?

The site is currently just a static site and you can see it here to see what I'm talkin about:

http://www.thejackals.co.uk/

Any suggestions/help much appreciated.

Simon

Thumbs up

2

Re: Menu with (text) sub-headings.

SimonLove wrote:

My Question is this: How do I alter the menu php code so that when I create pages, they go into the correct catergory?

Hi Simon -

There are a couple ways to do this: the "obvious" way wink and a ... less obvious way!

First -- the obvious option. I assume you have (or will) set up the pages this way:

Home [root]
  |
  |- What's Happening
  |     |- Gigs
  |     |- Setlist
  |     |- News (?), etc...
  |
  |- The Band
  |     |- Steve
  |     |- Jez
  |     |- Bass
  |     |- Drums
  |
  |- Sounds
        |- Sample
        |- Clip, etc...

If you do that, you can use the page-structure itself to do the "categorizing" for you. This is the way we would expect the system to be used. If so, I expect you would probably want to move "News" out to it's own "top" level (directly under Home/"root") so that your news items aren't too "buried".

The less obvious way would be to "tag" the pages with your categories, and there is some code in the wiki that would get you started. HOWEVER! This is cumbersome, and not really the purpose of the "tags". It would let you put ALL your pages at the "top" level, though.

I strongly recommend the first option! I mention the second only because it is "possible". It is not, however, desirable!

Hopefully your default Wolf installation will already give you an idea about how the page structure works. (See also the page drag-drop notes in the wiki.)

And let us know how you get on!

3

Re: Menu with (text) sub-headings.

By the way - assuming you use the "obvious" approach wink here's the code you could use. Make a new snippet called, for example, "side-nav", and copy/paste this in (leave filter as "-none-"):

<ul id="side-nav">
<?php foreach ($this->find('/')->children() as $child): ?>
    <li><?php echo $child->link($child->title, (url_start_with($child->url) ? ' class="current"': null)); ?>
<?php if (count($this->find($child->slug())->children()) > 0 ) : ?>
<ul>
<?php foreach ($this->find($child->slug())->children() as $grandchild) : ?>
    <li><?php echo $grandchild->link($grandchild->title, (url_start_with($grandchild->url) ? ' class="current"': null)); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>

and save. Then, in the sidebar of your layout, put in this line where you want your menu:

<?php $this->includeSnippet('side-nav'); ?>

And that should be you. You'll want some CSS for the menu, but you knew that already!

Re: Menu with (text) sub-headings.

Hi

Thanks very much that will be useful for another project I'm sure. However, that's not really what I'm after:

I don't want 'What's Happening', 'The Band' and 'Sounds' to be URLs. I want them to be as they are at the moment(text).

Is there some way I could have say three separate divs in the nav column each with it's own links? Could I do it that way?

Simon

Thumbs up

Re: Menu with (text) sub-headings.

Its the same code David gave you, but with some minor changes:

<div id="side-nav">
<?php foreach ($this->find('/')->children() as $child): ?>
<div class="foo">
<h2><?php echo $child->title; ?></h2>
<?php if (count($this->find($child->slug())->children()) > 0 ) : ?>
<ul>
<?php foreach ($this->find($child->slug())->children() as $grandchild) : ?>
    <li><?php echo $grandchild->link($grandchild->title, (url_start_with($grandchild->url) ? ' class="current"': null)); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>

Last edited by Fortron (2010-09-06 01:21)

6

Re: Menu with (text) sub-headings.

I think Fortron has nailed it -- you just might want to change the DIV line (line 3) to read this way:

<div class="<?php echo $child->slug; ?>">

which will automatically generate a unique Class for each of the DIVs, based on the parent's slug.

HTH!

Re: Menu with (text) sub-headings.

David wrote:
<div class="<?php echo $child->slug; ?>">

Well since above code gives it a unique name and there will be likely to be only one element on a page by that name, then using a id will be more appropriate:

<div id="<?php echo $child->slug; ?>">

But that is my opinion, I personally use id's when I know there will be only one on each page.

8

Re: Menu with (text) sub-headings.

@Fortron - my normal practice would the same as yours (unique divs = ID rather than CLASS), but I was responding to this...

SimonLove wrote:

Is there some way I could have say three separate divs in the nav column each with it's own links? Could I do it that way?

...which on reflection, I think I slightly misunderstood in my caffeine-deprived state this morning. You're quite right: a single class could do the job nicely.

Re: Menu with (text) sub-headings.

I would be so bold as to state it should be considered Bad Practice(tm) when you use unique names for a CLASS. smile The ID field is intended for unique names and the CLASS field is intended for generic names.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.