Jump to content

Sidebar question


Fionnan
 Share

Recommended Posts

Hi all,

I love this CMS, very easy to use and does exactly what I want. I have a question regarding the sidebar though.

I want to have a static sidebar, similar to this thread http://processwire.com/talk/index.php/topic,63.0.html but I want to be able to have some of the children in the top menu and some on the sidebar instead of having the children listed on both.

Is this possible?

Link to comment
Share on other sites

Hi Fionnan,

everything is possible. Can you post some example site tree and how exactly [based on this example tree] you want the children split between two menus? I.E. calrify a little? So we can find the right key how to split the children or find the right code to what you want to do.

Link to comment
Share on other sites

Hi Adam,

Thanks for the quick reply. I'm trying to convert this site (http:www.thehsi.org/index.php) to Processwire.

You can see my poor attempt at it so far here lab.thehsi.org !!!

So you can see, I have quite a few child pages to go on the top and sides.

I tried the solution you gave to bhammeraz but it doesn't quite work for this, although its going in the right direction!

I'd appreciate any help you could give. Let me know if you need from snippets from the source etc..

Thanks,

Fionnan

Link to comment
Share on other sites

Hi,

my advice is generally simple: create structure like this [example]:

- subpage1
- subpage2
  - subpage 2.1
  - subpage 2.2
  - subpage 2.3
- subpage3
- important-information
 - membership
 - about us
 - the third thing

now, the code for your top menu should be:

 $data-for-foreach = $pages->find("parent=0|/important-information/");

and your left navigation:

 $data-for-foreach = $pages->get('/')->children('name!=important-information');

special left sublists:

 foreach($data-for-foreach as $p){
   addItem($p) //pseudocode, add your own menu adding routine
   if ($p->numChildren) {
     opensublist(); //pseudocode
     foreach($p->children as $c){
       addItem($c);
     }  
     closesublist(); //pseudocode
   }
 }

However, this will do a little different navigation then you currently have [i.e. you won't have the same styling, until you don't wrap single pages like 'Employment / Volunteer Opportunites *' into 'Opportunities' page.

Adam

Link to comment
Share on other sites

Most often the navigation structure of a site lines up pretty closely with your page structure. For example, your top navigation might consist of your root level of pages (those having the homepage "/" as their parent). And those in the sidebar might be under some section like /tools/. So the way you'd print you top nav would be like this:

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

Then your subnav:

<?php
$subnav = $pages->get("/tools/")->children(); // OR $pages->find("parent=/tools/"); 
echo $subnav->render(); // OR output them manually like in $topnav

But lets say that your site structure doesn't lend itself well to this. What you might want to do is add a checkbox field to your template so that you can mark what pages should appear in the nav. For instance, you might add a field called "toggle_topnav" and another called "toggle_subnav". When you edit the page, you would check the box for one or another if you wanted it to appear in the navigation. Then you'd get your $topnav and $subnav like this:

<?php
$topnav = $pages->find("toggle_topnav=1");
$subav = $pages->find("toggle_subnav=1"); 

And you'd output them using whatever manner you prefer (examples above).

Lastly, don't be afraid to hard-code navigation markup. If it's something the client doesn't need to change, it is more efficient to hard-code it rather than generate it dynamically.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...