FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Submenus

Feed 39 posts, 8 voices

Avatar
30 posts

Hey,

I was wondering if there would be any easy way of displaying submenus in the header as a dropdown menu or somewhere on the sidebar?.

I appreciate your help on this one.

 
Avatar
1493 posts

Hi Mitnick:

This is how I did it:

  1. Click on the green + icon in the admin view of the page at the top of the tree for your submenus.
  2. Put "sidebar" in the pop-up box and click "Add"
  3. Click the "sidebar" tab (beside "body" tab) you have just added.
  4. Put this code into the sidebar:

    <h3>Sidebar Title</h3> <?php $page_submenu = $this->find('/YOUR-PAGE-HERE/'); ?> <ul> <?php foreach ($page_submenu ->children(array()) as $menuPage): ?> <li><?php echo $menuPage->link() ?></li> <?php endforeach; ?> </ul>

Notes: where I have "YOUR-PAGE-HERE", put in the "slug" of the page this sidebar is attached to (find the slug under the "Metadata" link).

I think that should work! :) I have made the variables more "abstract" here than in my actual page, so I hope it's all OK.

Let us know how you get on.

 
Avatar
1493 posts

Markdown didn't like the way I put in the code! I'll try again:

<pre><code> <h3>Sidebar Title</h3> <?php $page_submenu = $this->find('/YOUR-PAGE-HERE/'); ?> <ul> <?php foreach ($page_submenu ->children(array()) as $menuPage): ?> <li><?php echo $menuPage->link() ?></li> <?php endforeach; ?> </ul> </code></pre>

 
Avatar
1493 posts

Right. Something funny going on here. I'll try one more time, and if this doesn't work, I'll leave it for Philippe to clean up! :)

<h3>Sidebar Title</h3> <?php $page_submenu = $this->find('/YOUR-PAGE-HERE/'); ?> <ul> <?php foreach ($page_submenu ->children(array()) as $menuPage): ?> <li><?php echo $menuPage->link() ?></li> <?php endforeach; ?> </ul>

 
Avatar
1493 posts

Grrr.... Here's a pic:

!sidebar menu code

 
Avatar
541 posts

Haha David .. use 4 spaces or a tab before your code to be set as code ;)

<h3>Sidebar Title</h3>
<?php $page_submenu = $this->find('/YOUR-PAGE-HERE/'); ?>
<ul>
<?php foreach ($page_submenu ->children(array()) as $menuPage): ?>
    <li><?php echo $menuPage->link() ?></li>
<?php endforeach; ?>
</ul>
 
Avatar
541 posts

and not only before the first line, before each line !

 
Avatar
1493 posts

> use 4 spaces or a tab before your code to be set as code ;)

I thought I did that the first time!? Maybe I only had three.... At least I know now it is supposed to work!

 
Avatar
30 posts

Wow, thanks for the feedback guys. Is there any way i can make submenus as a dropdown menu from the existing menu ?.

 
Avatar
56 posts

I can think of a couple of ways you can do that. Fancy CSS and a bit of PHP, mainly. :D

BUT, I have to ask: why do you want to have submenus? There's an age-old mantra with site design: "Everything should be accessible within 3 clicks from the home page." Keeping in mind that sub-menus annoy users more often than not, and will not always show up in every browser (no matter how you do them), they are not an end-run around the mantra.

I have learned that, as a rule, submenus tend to go fairly unused by end-users. They only serve as a convenience for the site designer. You would not believe how many times I've heard things like "I wish people would just READ the pages I put up!", only to discover that the pages in question are only available via a submenu (or, worse, a search).

Also, another rule of thumb: if you do have to use a submenu for some reason (corporate mandate, for example), keep it 3-5 items short. Less than 3, and it is pointless. More than 5, and users will be overwhelmed.

In my opinion, almost every instance of a site with submenus can be better designed with a better structure and contextual links.

As an example: Let's say that you have a "Products" page with 8 products. One thing you will see companies do often is have a submenu with each of the products. That solves that, right? After all, you can get to each of the products, right? Well, no.

You see, 8 products is enough to confuse the average user (pretend that your average end-user is an untrained monkey, it makes for easier site design). Especially if you have different "editions" of your products. Or if you have similarly named products. These are common cases.

How will the average end-user know which to pick? They won't. They will just choose one. And usually choose wrong. And get frustrated. And go to a competitor with a better site, not telling you why they never even downloaded.

So, what can you do to fix it? In this case, have a single Products page in the navigation. On this page, you can list your products. I find that enumerating in a fashion like this (for a Products example) works well: (And I hope Markdown cooperates…)

  • Product Name — This is where the product description goes. Don't go into too much detail, just enough to help the customer differentiate the choices. Then, follow with a set of links. Features Pricing Try Buy

Also, having a comparison chart on that page, with appropriate links (feature-specific pages, buy/try/download links, links to the product pages, etc.) embedded in the chart works very well.

With the above, you manage to avoid the clutter and general confusion generated by submenus. I chose a "Products" page as an example, as almost everyone has come across both good and bad examples of them. ;) But, the same concept holds true regardless of the type of page.

If you want to see an excellent example of a well-done Products page, let me know and I'll track one down. (One that I have no connection with, even! ;) ) Unfortunately, most well-done pages don't get the recognition they deserve by "Corporate", as the mandate tends to be sub-menus, and those who write the mandates seem to never look at the main pages in the menu. That's no excuse for being a good web designer and helping your customers, in spite of your policymakers, though! ;)

Also, since Frog has built-in support for sidebars, use them to your advantage! Since your "main" page for the group will be more trafficked now than otherwise, feel free to put news, promotions, anything else that your captive audience may appreciate.

If, in spite of all this, you still insist on a submenu, let me know. I'll poke at the CSS to see if I can't figure out how to do it with Frog. But, the basic idea is that you make an unordered list and show it only when you hover over the list item in the header. You can use the same sidebar code (practically unmodified) to generate the list in your header. The hard part is the CSS! ;)

 
Avatar
30 posts

Hey Lewellyn,

Thanks for the advice, i think you have a point there. I have decided to but the submenu in the sidebar, there is just one thing now. How can i make the sidebar menu recognize "a.current" ?

 
Avatar
30 posts

And one more thing :)

How can i make the submenu recognize this setup

ROOTMENU - SUBMENU - SUBMENU - SUBSUBMENU - SUBSUBSUBMENU - SUBSUBMENU - SUBMENU - SUBMENU

Any ideas ?..

 
Avatar
30 posts

And one more thing :)

How can i make the submenu recognize this setup

ROOTMENU 

- SUBMENU - SUBMENU - SUBSUBMENU - SUBSUBSUBMENU - SUBSUBMENU - SUBMENU - SUBMENU

Any ideas ?..

 
Avatar
30 posts

Omg, it´s now showing right!!.

Well my point is that i need to use 3 levels of the submenu.

 
Avatar
1493 posts

One of the PHP hard men needs to solve this. Philippe has a level() function that might help here, but I don't know how to use it. Also, nested foreach statements (that seemed one way forward) are either tricky (or impossible) and might require a multidimensional array (!) using a single foreach with "keys" -- and that is waaaay beyond me.

Here is one simple way to do it, but it involves manually putting the PHP submenu and sub-submenu code in the sidebars of the relevant pages. Say you have a site structure like this:

Home [0]
|
PageOne [1]
|
PageTwo [1] 
|
|- Two-SubA [2]
  |
  |- Two-SubA-Sub1 [3]
  |
  |- Two-SubA-Sub2 [3]
  |
|- Two-SubB [2]
|
PageThree [1]
|
etc.

The main site nav takes care of level [0] and [1]. In the sidebar of PageTwo, you include the code we used before:

<h3>Sidebar Title</h3>
<?php $page_submenu = $this->find('/YOUR-PAGE-HERE/'); ?>
<ul>
<?php foreach ($page_submenu ->children(array()) as $menuPage): ?>
  <li><?php echo $menuPage->link() ?></li>
<?php endforeach; ?>
</ul>

But in the sidebar of Two-SubA (that will have a sub-submenu), include BOTH the following:

<h3>Sidebar Title</h3>
<?php $page_submenu = $this->find('/YOUR-PAGE-HERE/'); ?>
<ul>
<?php foreach ($page_submenu ->children(array()) as $menuPage): ?>
  <li><?php echo $menuPage->link() ?></li>
<?php endforeach; ?>
</ul>

<h3>Extra Submenu</h3>
<?php $next_submenu = $this->find('/YOUR-PAGE-HERE/SUB-PAGE-HERE/'); ?>
<ul>
<?php foreach ($next_submenu ->children(array()) as $nextPage): ?>
  <li><?php echo $nextPage->link() ?></li>
<?php endforeach; ?>
</ul>

And that (I think!!!) will work. It's working for me, anyway.

As I say, there must be a way of detecting this and making it all a single, elegant submenu on the level [1] page, but meanwhile, this should at least help! I hope....

(And if the code does not work in the forum, I will cry!) (There is a tab before each line of code ... I promise!)

 
Avatar
1493 posts

Woo hoo! The code worked! :))

Also, I meant to say: in the Extra Submenu section above, where you get this line:

<?php $page_submenu = $this->find('/YOUR-PAGE-HERE/SUB-PAGE-HERE/'); ?>

you need to put the slug for the level [1] page, and the level [2] page. If it was the same as the tree diagram above, it would be something like:

<?php $page_submenu = $this->find('/page2/two-suba/'); ?>

or something like that. I hope you see what I mean!

 
Avatar
1493 posts

I am trying to set up an "abstract" version that will test the URL and return the correct submenu with/without sub-submenu depending on whether level[2] has children. Not that with the explode method, it gets a bit confusing because position [3] in the array = level [2] in my tree above! Anyway, this DOES NOT WORK:

<?php $subPageId = explode('/', $_SERVER['REQUEST_URI']);
$level2=$subPageId[2]; $level3=$subPageId[3]; ?>

<h3>Sidbebar Title</h3>
<?php $page2 = $this->find($level2); ?>
<ul>
<?php foreach ($page2->children(array()) as $menu2): ?>
    <li><?php echo $menu2->link(); ?></li>
<?php endforeach; ?>
</ul>

<?php $level3->children(array()) as $test3; 
$count3 = count($test3);
switch ($count3) {
    case 0: break;
    default: ?>
    <h3>More Menu</h3>
    <?php $page3 = $this->find($level3); ?>
    <ul>
    <?php foreach ($page3->children(array()) as $menu3): ?>
        <li><?php echo $menu3->link(); ?></li>
    <?php endforeach; ?>
    </ul>
<?php break; } ?>

But I hope you can see what I'm trying to do: in the sub-submen, I am getting the array for children, and counting them. If the count == 0, then nothing happens (break); but otherwise you get a sub-submenu. That's the idea, but it is not working.

Does anyone else want to try???

 
Avatar
1493 posts

(Can we get an "edit post" function, Philippe?! ;) )

In the second sentence above, "Not that with the..." should read "NotE that with the...". Sorry.

 
Avatar
1493 posts

Or maybe try to adapt Philippe's nifty new "sitemenu" (see the FAQ part of this forum) code? There might be a way of making it match only a certain branch of the tree? Maybe ... I'm just guessing......

 
Avatar
541 posts

Humm maybe I can do that. It will be my christmas gift for you :P

 
Avatar
30 posts

Wow, thanks guyes. Just what i was looking for..

 
Avatar
27 posts

I use Philippe's sitemap function to generate a navigation tree. In my case it didn't need to be contextual (all of the tree is always visible).

 
Avatar
191 posts

I'm in the learning stages of Frog, and found this thread as I was searching for navigation options. I would like to use Suckerfish type drop down menus with Frog. Will Frog support Suckerfish?

From what I read above, I believe it will, I just need to learn the syntax to produce the nested list. Is that correct? I plan to create a horizontal navigation bar, with each item on the navigation bar having a vertical drop down menu on hover.

Note: I've never used Markdown before, and hope I figured out the syntax correctly for the link to the Suckerfish menus.

 
Avatar
541 posts

Suckerfish is a client part (CSS) with a relativly simple list structure. So I will say yes you can do the list for your suckerfish drop down.

You will have to pass trow 2 "imbricked" foreach and create the nested list.

You markdown is correct :), my english is so so .. I do my best!!

 
Avatar
1493 posts

This seems to work fine! Here's what I did:

  • I grabbed the two-level drop-down CSS and related code from this site
  • made a new CSS file, just replaced the nav markup with the suckerfish CSS :)
  • made a new layout (I called it "Normal_ddnav") that called the new css (styles_ddnav.css, of course), and included the "suckerfish" script in the head
  • created a sitemap in Frog following these instructions
  • made a new header snipped ... called header_ddnav, in which I called the sitemap with <a href="<?php echo BASE_URL; ?>sitemap">Sitemap</a> replacing everything that was in the nav DIV, and...

...it all worked! Works in FF, Opera 9.2, and IE6, anyway. Not too shabby.

Hope that helps! WARNING! I am typing this very quickly and may well have missed out something crucial! :) Hope not, though.

David.