Topic: Menu - Show Child Menu

Hi,

I have the following structure:

Home - North - South - News - About Us - Product Catalogue - Contact Us

But if I click on North then it needs to show:

Home - Economic Review - Our Services - Who we Help - Staying Profitable - News - About us - Contact Us (Which are the children of North...

Any ideas?

Thumbs up

Re: Menu - Show Child Menu

Check here first: http://www.wolfcms.org/wiki/navigational_cookbook

Wolf CMS Paper Guy
Wolf CMS related blog / journal at Project 79 | Wolf CMS Docs

3

Re: Menu - Show Child Menu

wickedwebsites wrote:

Any ideas?

The link jackie gave you is the "motherlode" -- but do also see the "conditional navigation" bit in the "Wolf" layout that Wolf has "out of the box". That is intended to provide exactly that kind of menu for you.

Re: Menu - Show Child Menu

Hi again both of you smile

Thank you for this link, I have used it, however I only need it to go Top Level --> Child Level,

At the moment, I have

Home | North | South | Contact

I click on North

Home | Review | Services | Help | Profitable | Contact

that should stop there, but if I now click on Review I then get

Home | Contact

but I need to see the same as North,

Can you limit to one child area?

Thumbs up

5

Re: Menu - Show Child Menu

wickedwebsites wrote:

... I click on North

Home | Review | Services | Help | Profitable | Contact

that should stop there, but if I now click on Review I then get

Home | Contact

but I need to see the same as North,

Can you limit to one child area?

There are ways of limiting the navigation to one child area, but I'm not sure I'm correctly picturing what's happening in your site. Is it live online where we could see what's happening?

One thing that comes to mind is the "perpetual" navigation, of which there is a "horizontal" and "vertical" example in the Navigational Cookbook. They specialize in giving you "children-of-where-I-am-now-only" navigation -- but as I say, perhaps this isn't what you have in mind.

Re: Menu - Show Child Menu

hi David,

Have a look at www.taxbusters.eu.com/wolfcms

Click on Northern Ireland

The nav bar now changes, this bar needs to be shown on all pages inside the Northern Ireland area, i.e. click on Economic Review.

All the page links on the nav bar have disappeared, but it needs to show all the navs for the northern ireland section.

This is excellent software smile

Thumbs up

7

Re: Menu - Show Child Menu

wickedwebsites wrote:

... All the page links on the nav bar have disappeared, but it needs to show all the navs for the northern ireland section. ...

Ah, right! When you're on the "grandchild" (of Home) page, you still need the menu of its parent to show.

In fact, that "conditional navigation" code from the Wolf layout does precisely this (mentioned in post #3, above). If you need help adapting it ... maybe we could give you a hand off-forum!

Re: Menu - Show Child Menu

David wrote:
wickedwebsites wrote:

... All the page links on the nav bar have disappeared, but it needs to show all the navs for the northern ireland section. ...

Ah, right! When you're on the "grandchild" (of Home) page, you still need the menu of its parent to show.

In fact, that "conditional navigation" code from the Wolf layout does precisely this (mentioned in post #3, above). If you need help adapting it ... maybe we could give you a hand off-forum!

thank you for the offer smile I'm getting my head around the code now, however I've changed the template system so much I cannot find the original nav code?

Is there a code snippet area I can grab it from?

Thumbs up

Re: Menu - Show Child Menu

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"
<?php echo url_match('/') ? '': ' id="current"'; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a>
      </td>
<?php foreach ($this->children() as $child): ?>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar">
      <?php echo $child->link($child->title, (url_start_with($child->url) ? ' class="current"': null)); ?></td>
<?php endforeach; ?>
      
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/news')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/about-us')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/contact-us')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/buy-online')->link(); ?></td>
</tr>
      </table>

this is the current code,

Last edited by wickedwebsites (2010-03-19 22:43)

Thumbs up

10

Re: Menu - Show Child Menu

wickedwebsites wrote:

....however I've changed the template system so much I cannot find the original nav code?

Is there a code snippet area I can grab it from?

I'll have a look at the code you posted; that gives us something to go on!

Meanwhile, I could have sworn I posted a link to the Wolf-layout conditional nav code (commented version), but I don't see it here anymore! Odd. hmm

11

Re: Menu - Show Child Menu

WARNING! Untested! But you could give this a try:

<?php if ($this->level() > 0) { $parent = reset(explode('/', CURRENT_URI)); $topPage = $this->find($parent); } ?>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"
<?php echo url_match('/') ? '': ' id="current"'; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a>
      </td>
<?php if ($this->level() == 0) : ?>
<?php foreach ($this->children() as $child): ?>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar">
      <?php echo $child->link($child->title, (url_start_with($child->url) ? ' class="current"': null)); ?></td>
<?php endforeach; ?>
<?php elseif (count($topPage->children()) > 0 &&  $topPage->slug() != 'news') : ?>
<?php foreach ($topPage->children() as $subPage): ?>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar">
      <?php echo $subPage->link($subPage->title, (url_start_with($subPage->url) ? ' class="current"': null)); ?></td>
<?php endforeach; ?>
<?php endif; ?>     
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/news')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/about-us')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/contact-us')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav-bar1.jpg" class="navbar"><?php echo $this->find('/buy-online')->link(); ?></td>
</tr>
      </table>

Let us know if anything blows up! wink

[Edit - code corrected, as noted below]

Last edited by David (2010-03-20 21:56)

Re: Menu - Show Child Menu

well, no broken windows or shattered bones, however it seems like nothing changed at all?

it has the same effect, hmmm, I think I'll go and rtfm now and see if i can work it out lol

Thumbs up

13

Re: Menu - Show Child Menu

wickedwebsites wrote:

... however it seems like nothing changed at all? ...

Drat! That's what comes of doing something quickly before shutting the comp off for the night! roll

Try this: change this line (I make it line 7):

<?php if ($this->level() > 0) : ?>

to this:

<?php if ($this->level() == 0) : ?>

And see what happens then.

Re: Menu - Show Child Menu

Excellent!!!!

Thank you so much, could you just explain what the change in the code did, (I'm stilll learning) smile

Thumbs up

15

Re: Menu - Show Child Menu

wickedwebsites wrote:

... could you just explain what the change in the code did, (I'm stilll learning) smile

I know that feeling, because I am too!

A bit of commentary: the "if" in the first line sets the $topPage variable *if* we are NOT on the homepage. Since "Home" is the only page at "level 0", whenever you're anywhere else, this variable sets the "area" of the site you are in (e.g., "North"). It is self-contained, so doesn't need a corresponding "endif".

The next "if" is the one we needed to change. I had left in a "greater than" test from the code I was stealing this from. What I really wanted was "==", which is a PHP's way of saying "if the value is equal to..." (a single "=" assigns a value). So here we're saying "if the level is == 0, then we're on the homepage, so give us the standard navigation items". And that's what the next "foreach" bit does.

Then comes the "elseif": which means here "else, if we're not at level 0" (which is the "home" level), then use that $topPage variable to generate the navigation, which it does with the next "foreach" bit. Since $topPage knows that we're in "North" or "South", or whatever, we get that navigation, even if we go further into the page structure (where we were losing the navigation items before).

(Within the "elseif", there is a second test ("&&...") which keeps this nav off your "news" page, too. That's a bit of a crude test, and you may well want to tweak that bit!)

The "if... elseif..." still needs to be "closed", so we have that final "endif" to let PHP know we're done with the tests for now.

Hope that helps to make sense of the code! The explanations may not be 100% precise, but possibly they will do. wink

Btw, you can find a full commentary explaining the default nav code in the wiki. That might make a good partner with this post if you're still feeling your way.

Hope that helps!

Re: Menu - Show Child Menu

Ok, maybe I spoke too soon...

I'm slightly lost now, I access http://taxbusters.eu.com/wolfcms/?northern-ireland.html

I only get the header, I get no page content at all...

northheader snippet

<table width="1024" height="1381" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
  <tr>
    <td height="1381" valign="top"> 
      <table width="1024" height="167" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="167" align="left" valign="middle" background="http://www.taxbusters.eu.com/images/header.jpg"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','335','height','125','hspace','20','src','http://www.taxbusters.eu.com/swf/taxbusters','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','http://www.taxbusters.eu.com/swf/taxbusters' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="335" height="125" hspace="20">
            <param name="movie" value="http://www.taxbusters.eu.com/swf/taxbusters.swf">
            <param name="quality" value="high">
            <embed src="http://www.taxbusters.eu.com/swf/taxbusters.swf" width="335" height="125" hspace="20" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>
          </object></noscript></td>
        </tr>
      </table>
      <?php if ($this->level() > 0) { $parent = reset(explode('/', CURRENT_URI)); $topPage = $this->find($parent); } ?>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar"
<?php echo url_match('/') ? '': ' id="current"'; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a>
      </td>
    <?php if ($this->level() == 0) : ?>
<?php foreach ($this->children() as $child): ?>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar">
      <?php echo $child->link($child->title, (url_start_with($child->url) ? ' class="current"': null)); ?></td>
<?php endforeach; ?>
<?php elseif (count($topPage->children()) > 0 &&  $topPage->slug() != 'news') : ?>
<?php foreach ($topPage->children() as $subPage): ?>
      <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar">
      <?php echo $subPage->link($subPage->title, (url_start_with($subPage->url) ? ' class="current"': null)); ?></td>
<?php endforeach; ?>
<?php endif; ?> 
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar"><?php echo $this->find('/news')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar"><?php echo $this->find('/about-us')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar"><?php echo $this->find('/contact-us')->link(); ?></td>
     <td height="43" align="center" background="http://www.taxbusters.eu.com/images/nav_back.jpg" class="navbar"><?php echo $this->find('/buy-online')->link(); ?></td>
</tr>
      </table>

This it the north pages layout

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title><?php echo $this->title(); ?></title>
  <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
  <meta name="robots" content="index, follow" />
  <meta name="description" content="<?php echo ($this->description() != '') ? $this->description() : 'Default description goes here'; ?>" />
  <meta name="keywords" content="<?php echo ($this->keywords() != '') ? $this->keywords() : 'default, keywords, here'; ?>" />
  <meta name="author" content="Author Name" />
    <link rel="favourites icon" href="<?php echo URL_PUBLIC; ?>favicon.ico" />
    <link rel="stylesheet" href="<?php echo URL_PUBLIC; ?>public/themes/simple/screen.css" media="screen" type="text/css" />
    <link rel="stylesheet" href="<?php echo URL_PUBLIC; ?>public/themes/simple/print.css" media="print" type="text/css" />
    <link type="text/css" href="http://www.taxbusters.eu.com/CSS/style.css" rel="stylesheet" />
    <link rel="alternate" type="application/rss+xml" title="Wolf Default RSS Feed" href="<?php echo URL_PUBLIC.((USE_MOD_REWRITE)?'':'/?'); ?>rss.xml" />
  <script src="http://www.taxbusters.eu.com/scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body>
<div id="page">
<?php $this->includeSnippet('northheader'); ?>

<div id="content"><br>
<table width="1024" height="1033" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr bgcolor="#FFFFFF"> 
          <td width="33" height="1033">&nbsp;</td>
          <td valign="top"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="37" background="http://taxbusters.eu.com/images/blank_heading.jpg">&nbsp;<span class="heading3"><?php echo $this->title(); ?></span></td>
              </tr>
            </table>
<span class="text1">
  <?php echo $this->content(); ?> 
  <?php if ($this->hasContent('extended')) echo $this->content('extended'); ?> 
</span></td>
          <td width="33">&nbsp;</td>
          <td width="243" valign="top"> 
            <table width="232" height="279" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td align="center" background="http://taxbusters.eu.com/images/tax-return.jpg"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td height="36">&nbsp;</td>
                    </tr>
                    <tr>
                      <td height="219" align="center"><a href="#"><img src="http://taxbusters.eu.com/images/clock.jpg" width="169" height="209" border="0"></a></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
              </tr>
            </table>
            <table width="80%" height="28" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table>
            <table width="232" height="227" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td><a href="page.php?id=9"><img src="http://taxbusters.eu.com/images/where-to-find-us.jpg" width="232" height="227" border="0"></a></td>
              </tr>
            </table>
            <table width="80%" height="27" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table>
            <table width="234" height="414" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td><img src="http://taxbusters.eu.com/images/side-image.jpg" width="234" height="414"></td>
              </tr>
            </table>
            <p>&nbsp;</p></td>
          <td width="35">&nbsp;</td>
        </tr>
      </table>
</div> <!-- end #content -->
<?php $this->includeSnippet('footer'); ?>
</div> <!-- end #page -->
</body>
</html>

Any thing I've missed?

Thumbs up

17

Re: Menu - Show Child Menu

The immediate problem is that you seem to have moved the "News" page, is that right? Your hard-set links are looking for a "News" page which no longer exists in the main nav, and that is breaking the layout.

Meanwhile, I think you are making things more complicated than necessary! When I visited your site, I got the correct menu for "North", but not "South", which struck me as impossible...

... but I think I see what you might be doing.

That code I gave you should go in ONE LAYOUT ONLY. It has built-in checks to know which page you're on, and which part of the website you're in. Your whole site only needs a single layout! You only need one "header" snippet with the navigation code, etc. (Not a separate one for "North", "South", and so on.)

(It's been a long time since I've seen a table-based layout, too, fwiw! wink )

Perhaps you could review that code commentary linked above, and have a look at the theme tutorial in the wiki; it might help a bit with an approach to the task! Another thing to look over is the two default layouts that come with Wolf, to see how they set things up.

Re: Menu - Show Child Menu

Hey,

Ok, I changed the North section to use the same layout file as my main home page, however if I go to north, I dont get the headings for north, I just get the top level pages?

Thumbs up

19

Re: Menu - Show Child Menu

Hi w2 - It's hard to say what's going on without actually looking at your code. I'm getting the impression that you're putting things in places I wouldn't expect wink so it could be that my "help" is turning out to be not so helpful!

If you're willing, I'd be happy to have a look at what's going on if you want to give me a guest login to your site. Use the "email" link from this forum to shoot me a note -- if you're interested -- and we can be in touch directly.