Jump to content


Photo

Multiple menus


  • Please log in to reply
30 replies to this topic

#1 tsd

tsd

    Jr. Member

  • Members
  • PipPip
  • 24 posts
  • 4

Posted 06 December 2011 - 07:52 AM

Hi,

I still can't figure out how to create multiple navigations.
Let's say I have this structure:

Home
  About
  Products
  Contact *
  Legal *
  Other Stuff (Hidden)

Contact and Legal should be in a footer navigation, rest in default main navigation. "Other stuff" is hidden already.
Decision by template is not an option because the real structure has a lot more pages/templates and I think it's inefficient to manually ad new templates to the menu modules/templates each time. Also I have pages with the same template but which should show in different menus.

Next option is to add a field in every template to identify if this page should be rendered in top or footer navigation. Would work, but I don't like it :)

How do you guys beat this challange?

#2 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 06 December 2011 - 08:20 AM

Next option is to add a field in every template to identify if this page should be rendered in top or footer navigation. Would work, but I don't like it :)


Why not? Actually pretty fine solution to add it in page to be able to say where it should go.

There's actually some different ways you could archive something like this.
- add a field for selecting what navigation the page should go.
- add a structure to define navigation. Special type of pages where you can select what page should have link in footer navigation.
- same but only one page with page reference field
- add the 2-3 links manually to the footer nav code. And make them hidden in admin.
- by a special template for footer pages.


@somartist | modules created | support me, flattr my work flattr.com


#3 Pete

Pete

    Administrator

  • Administrators
  • 1,754 posts
  • 652

  • LocationChester, England

Posted 06 December 2011 - 08:23 AM

The other option is to do a normal menu and if it's ONLY those two pages you don't want to appear then exclude them using the API selectors.

#4 tsd

tsd

    Jr. Member

  • Members
  • PipPip
  • 24 posts
  • 4

Posted 06 December 2011 - 08:31 AM

There's actually some different ways you could archive something like this.
- add a field for selecting what navigation the page should go.
- add a structure to define navigation. Special type of pages where you can select what page should have link in footer navigation.
- same but only one page with page reference field
- add the 2-3 links manually to the footer nav code. And make them hidden in admin.
- by a special template for footer pages.


Plenty of options. Thank you, I think I can work with that.

#5 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 06 December 2011 - 08:34 AM

tsd, if you need more help just ask here. I'm sure we can find a solution that suits your needs. But first try out and think what would be best for you. Let us know what you come up with using. :)

@somartist | modules created | support me, flattr my work flattr.com


#6 tsd

tsd

    Jr. Member

  • Members
  • PipPip
  • 24 posts
  • 4

Posted 06 December 2011 - 08:38 AM

I can't really describe why I don't like the extra field to choose if this page is a main or footer navigation page.

I think I will go with a extra structure for the menus. It's more flexible when you need to add new stuff or edit. I'll try it out tonight.

You're very helpful, thank you!

#7 nikola

nikola

    Sr. Member

  • Members
  • PipPipPipPip
  • 224 posts
  • 81

  • LocationZagreb, Croatia

Posted 06 December 2011 - 12:11 PM

tsd, you can do something like this for header navigation (if you add extra pages to header navigation, they will show normally):

<?php
        
    echo "<ul>";
        
    $headerNav = $pages->get('/');
        
    foreach($headerNav->children as $menu) {
    $class = $menu === $page->rootParent ? " class='active'" : '';

    if ($menu->name != 'contact' && $menu->name != 'legal') {
        echo "<li><a$class href='{$menu->url}'>{$menu->title}</a>";	
       }
    }

    echo "</ul>";


As far for footer navigation you can do something like this:

<?php
        
    echo "<ul>";
        
    $footerNav = $pages->get('/');
        
    foreach($footerNav->children as $menu) {
    $class = $menu === $page->rootParent ? " class='active'" : '';
    
    if ($menu->name == 'contact' || $menu->name == 'legal') {
        echo "<li><a$class href='{$menu->url}'>{$menu->title}</a>";	
        }
    }

    echo "</ul>";
        

Hope it helps...
Check out my ProcessWire admin themes: Futura Remixed Admin Theme / Moderna Admin Theme / Futura Admin Theme

#8 ryan

ryan

    Hero Member

  • Administrators
  • 5,753 posts
  • 3102

  • LocationAtlanta, GA

Posted 06 December 2011 - 12:42 PM

Another way you can go is to use page reference fields. Add two new 'Page' reference fields: topnav and footnav. Make them support multiple pages. Don't restrict it to a parent or template. Select 'PageListSelectMultiple' as the Inputfield for them. Save, and add them to your Homepage template.

Now edit your homepage. For the 'topnav' field, select all the pages you want as part of your top navigation, and for the 'footnav' field select all the pages that should appear in your footer navigation. Drag to sort them in the order you want.

Edit your main markup file (or head/foot includes) and use the following code to output that navigation:

<?php
foreach($pages->get("/")->topnav as $item) {
   echo "<li><a href='{$item->url}'>{$item->title}</a></li>";
}

…repeat the same for the footer nav, except iterate the footnav (rather than topnav) field.

In the sites that I develop, I almost always have the footer nav hard coded in the main markup file (I don't usually need it to be dynamic). For when I need the topnav dynamic, I'm usually sticking to the site's root level structure for the navigation (iterating the non-hidden children of the homepage). You may need all this stuff to be dynamic, in which case there are a lot of options. But I just wanted to mention that you should only make stuff dynamic that needs to be. When stuff can be hard coded in a template file, it consumes fewer resources. So if you stick to a policy of hard coding stuff that changes rarely and doesn't need to be dynamic, then you'll benefit from better performance, use less energy, save more trees, etc. :)

#9 everfreecreative

everfreecreative

    Sr. Member

  • Members
  • PipPipPipPip
  • 106 posts
  • 43

  • LocationCT, USA

Posted 28 February 2012 - 04:21 PM

It seems like you should be able to accomplish this by restructuring your pages into something like this:

Home
Top Navigation

Page 1

Page 2

Page 3

Bottom Navigation

Page 4

Page 5

Page 6

404
Admin
Trash

And then looping through the children of each. I guess the problem with this is that you'd end up with ugly URLs like www.yoursite.com/top-navigation/page-1

Is there any way around that?

#10 Pete

Pete

    Administrator

  • Administrators
  • 1,754 posts
  • 652

  • LocationChester, England

Posted 28 February 2012 - 05:05 PM

Is there any way around that?


The simplest method has been mentioned - having an extra field for the template to choose whether or not it appears in the header or footer menu.

Personally, my take on that would be to assume that all pages will appear in the header menu and have the extra field simply be a checkbox labelled "show in footer menu".

That way you can easily output a header menu excluding pages with that checkbox selected, and output a footer menu for those pages with the checkbox selected.

This is of course just variations on what others have said further up the page, but with field widths being adjustable now, you could even do something like make the page title field be 80% wide, have the checkbox 20% wide and then when editing pages the checkbox will appear neatly at the top-right of the edit screen and not take up a lot of space at all (which I'm guessing is the original poster's main issue with it?) :)

#11 everfreecreative

everfreecreative

    Sr. Member

  • Members
  • PipPipPipPip
  • 106 posts
  • 43

  • LocationCT, USA

Posted 28 February 2012 - 05:20 PM

When I said "Is there any way around that" I was specifically referring to avoiding having the parent name added to the URL structure. Your solution is a good one as well, but it seems like it would be simpler, easier to visualize, and more scalable to just be able to divide up your menu structure. Then you could easily implement as many menus as you want.

#12 Pete

Pete

    Administrator

  • Administrators
  • 1,754 posts
  • 652

  • LocationChester, England

Posted 28 February 2012 - 05:43 PM

Hmm... I'm not sure there is a way around that to be honest. I originally thought of URL segments, but they only apply to things after the end of a URL.

I think the only way to do that would be some sort of custom module to override the way PW handles URLs, but that would be far more trouble than it's worth I suspect given the number of much easier alternatives available.

#13 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 28 February 2012 - 05:47 PM

Your content structure shouldn't be trying to completely reflect the menu structure how you want to appear on page through hierarchy. You're mixing things up. Just looking at your structure something feels wrong. The most elegant way, is to have a setting on page or various other options.

You could have a menu structure and a content structure. Then have a page ref field to select the page you want to render for a menu entry. Then use $page->render() to render the referenced page. And the url will be the one from the menu. Not sure how this would affect the handling on the menu heighlights. But I think there's ways to get it working. But at the end there would be some sort of base "dir" that you don't want to have in the address, so you're at the same point again. Although some clever custom handling of the urls outputted would maybe make it possible.

While this can be a desired situation to divide the structure but not have the structure reflect in the address, it would require URI routing. This could be done through htaccess, although this would require adapting the navigation urls you output from PW, think of headaches. Another way would be to have PW allow for configuring URI routes like in CI for example http://codeigniter.c...l/routing.html. Not sure how this all would work internally well regarding urls and the page finder functions etc. Though I also would like to hear from Ryan what he thinks about this subject, and if he sees anything possible like URI routing in the future in PW, as this subject popped up already in an other thread at least once.

@somartist | modules created | support me, flattr my work flattr.com


#14 diogo

diogo

    Hero Member

  • Moderators
  • 1,973 posts
  • 1059

  • LocationPorto, Portugal

Posted 28 February 2012 - 06:27 PM

And then looping through the children of each. I guess the problem with this is that you'd end up with ugly URLs like www.yoursite.com/top-navigation/page-1

Is there any way around that?


I agree with the others that this is not the right approach. But still, this can be answered, and there is a way around:
The name of the page on the tree is defined by the title, while the url segment is defined by the name. So, this would be as easy as having different name and title.

#15 everfreecreative

everfreecreative

    Sr. Member

  • Members
  • PipPipPipPip
  • 106 posts
  • 43

  • LocationCT, USA

Posted 28 February 2012 - 06:27 PM

Your content structure shouldn't be trying to completely reflect the menu structure how you want to appear on page through hierarchy.


Hmm... what should it reflect then? I thought that was the whole idea of keeping the menu structure and content together, as opposed to CMSs like Joomla and Drupal which require you to link your content with a separate menu item either during its creation or after.


Edit: If you do go the checkbox input field route, is it possible to give the checkbox a default value? For example, have a Main Menu checkbox that is checked by default and a Footer Menu checkbox which is unchecked by default? Ideally, I'd rather my clients not have to go through an extra step to get their content to appear.

#16 diogo

diogo

    Hero Member

  • Moderators
  • 1,973 posts
  • 1059

  • LocationPorto, Portugal

Posted 28 February 2012 - 06:35 PM

Hmm... what should it reflect then?


I would say that you can compare it with the separation of semantic markup and css, the tree structure should reflect the content logic and not the navigation. imagine that one day you want to change the way the content is presented on the webpage... that all the navigation would be rethinked... with this structure, you would have to keep the tree reflecting something that doesn't corresponds to the real situation.
Best, would be to organize the tree by content logic, and make the navigation work as you want on templates.

#17 everfreecreative

everfreecreative

    Sr. Member

  • Members
  • PipPipPipPip
  • 106 posts
  • 43

  • LocationCT, USA

Posted 28 February 2012 - 06:52 PM

I would say that you can compare it with the separation of semantic markup and css, the tree structure should reflect the content logic and not the navigation. imagine that one day you want to change the way the content is presented on the webpage... that all the navigation would be rethinked... with this structure, you would have to keep the tree reflecting something that doesn't corresponds to the real situation.
Best, would be to organize the tree by content logic, and make the navigation work as you want on templates.


Personally, I think that a well constructed content structure should make for a good navigational structure and vice versa. Separating them results in bizarre situations like you have in Joomla where articles can be categorized but it has no practical effect on how the site handles the content on the front end. This, in my experience, results in a difficult mental model that frustrates clients to no end. So It seems to me that PW has been developed to eliminate that sort of confusion. When you output your navigation onto the page, you basically spit out the content structure, with maybe some minor adjustments or repetitions here and there, but you're not picking and choosing pages one-by-one and forming a completely different navigational structure. I see this as a strength of PW. And PW makes it very easy to reorganize your content structure, so I don't see that as a concern.

I would be really interested to hear Ryan's take on this.


Edit: I do understand what you guys are saying--that the separation of navigational elements doesn't necessarily correlate with a difference in the underlying content structure. That being said, if your navigation is well thought out, the links in these navigation sections should have something in common with each other that makes them fit to be together. In other words, something about their content should dictate their placement and grouping. So while my previous example fails in that I use a physical page location as my parent item, I could just as easily group these items like so:

Home
Cars

Page 1

Page 2

Page 3

Boats

Page 1

Page 2

Page 3

404
Trash


And have the children of Cars show up in my main nav with the children of Boats in the footer. In this case, having /cars/ or /boats/ in my URL structure would not be so bad, because it is describing the content.

#18 diogo

diogo

    Hero Member

  • Moderators
  • 1,973 posts
  • 1059

  • LocationPorto, Portugal

Posted 28 February 2012 - 07:08 PM

If your content structure is well thought, you will automatically have a logical structure for the frontend as well as for the backend. What I'm saying is that you don't really have to think about it as "navigation1" and "navigation2", but as "products" and "articles" instead.

#19 everfreecreative

everfreecreative

    Sr. Member

  • Members
  • PipPipPipPip
  • 106 posts
  • 43

  • LocationCT, USA

Posted 28 February 2012 - 07:27 PM

If your content structure is well thought, you will automatically have a logical structure for the frontend as well as for the backend. What I'm saying is that you don't really have to think about it as "navigation1" and "navigation2", but as "products" and "articles" instead.


Exactly. Gotcha.

#20 Soma

Soma

    Hero Member

  • Moderators
  • 3,183 posts
  • 1733

  • LocationSH, Switzerland

Posted 28 February 2012 - 07:28 PM

Diogo already said it better than I could :D ...

What would gives you the reason to put a place of a content into a container called "/footer-navigation/"? Will those be special pages completely separate from the "main" navigation? So what if you find a more meaningful name that would put meaning to the content placed inside? mb /services/ ? ... In 99% of the projects I've worked on the so called footer, meta or service navigation are just a few "hard" coded into the template links that won't change a lot anyway. Also not areas where one would often add pages.

It's true that the content structure reflects the navigation 1:1 that what makes it easy to recognize as it represents the websites structure. Not layout related informations. Your approach is solely coming from the desire to give a visual structure to the editors to work with. That's what I meant by mixing up.

SO thinking about it a little more, I think some sort of visual named "separator" that can be but in between the pages inside the hierarchy might be a better solutions to this.

It's just the way PW works with it's hierarchical approach, and not every case and desire others might have, has been put into thought by Ryan or others. It's pretty much he's effort alone all of what you see in PW atm and done for he's needs and clients. It's still evolving and I think there will be some sort of solutions coming up. Just have to either wait or get active and try to get things discussed/done.

@somartist | modules created | support me, flattr my work flattr.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users