1

Topic: Submenu with child pages and grandchild pages as imbeded ul's

Hello,
I'm currently working on converting a static html website that I created in to a wolfCMS website; i'm not very experience in php, but i have a few different books i've been reading and using as reference. So obviously, i'm working on a menu for my website, the menu will be on all pages but the home page and will have the same basic links where ever it is.

The menu will always be formated like this:

(Current) | (Child Page) (GCh) | (Child Page)
                   (Child of Child)
                   (Child of Child)

At first I tried to make the code on my own but then i realized that i could probably modify the multilevel collapsing menu to fit my needs, since the mark up is almost identical. So I made some changes and it started to look like I thought it should but it doesn't print the children of the child pages. I know I'm missing something but i'm just not sure what, any help is appreciated.

Cookbook:Multilevel collapsing menu: http://www.wolfcms.org/wiki/navbook:stacking-collapsing
Webpage with my version of the code: http://waverlyxc.org/board.html

Thumbs up +2

2

Re: Submenu with child pages and grandchild pages as imbeded ul's

Hi d.pock, and welcome to the forums.

There do seem to be some odd things happening on your site. Can you confirm that (as the "stacking-collapsing" instructions state), you have saved that code to a snippet, and then called the snippet in your layout?

Also, did the code from the wiki work (aside from styling) before you made your changes?

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

3

Re: Submenu with child pages and grandchild pages as imbeded ul's

Hi,
I have the code saved as a snippet and the code i'm using is indeed from the wiki; other than the edits that I thought would get it working for me.

Thumbs up

4

Re: Submenu with child pages and grandchild pages as imbeded ul's

You didn't answer David's question... wink

David wrote:

Also, did the code from the wiki work (aside from styling) before you made your changes?

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 or see our financial report first.

5

Re: Submenu with child pages and grandchild pages as imbeded ul's

yeah, the code from the wiki works and is in the snippet, which is indeed imbedded into the layout.

Thumbs up

6

Re: Submenu with child pages and grandchild pages as imbeded ul's

<spock>Then logic would dictate the problem is in your custom/tweaked code.</spock>

Perhaps you can post the relevant snippet/code so we can take a closer look?

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 or see our financial report first.

7

Re: Submenu with child pages and grandchild pages as imbeded ul's

I've tried doing it multiple ways with about the same result; the most recent attempt is changing only the following lines:

$astack[1] = $this;
stackup($this, 1, $astack);
$bstack = array_reverse($astack);
$lev = count($bstack) - 1;
if ($lev == 1) echo '<ul><li>'.$bstack[1]->link('', 'class="current"')."\n";
else echo '<ul><li>'.$bstack[1]->link()."\n";

I think that I realize the reason it doesn't work as I expected, but I'm still not sure how to achieve what i want; if I'm correct, the changes I made only changed how it's displayed, instead of changing what level the menu starts on?

Thumbs up

8

Re: Submenu with child pages and grandchild pages as imbeded ul's

d.pock wrote:

I think that I realize the reason it doesn't work as I expected, but I'm still not sure how to achieve what i want...

I've spent a bit of time poking around your site. I'm not convinced that the "stacking/collapsing" codes is actually "what you want". Check out the sidebar navigation on this site to see the expected layout and behaviour (try clicking the "Work areas" link, and see what happens to the "Contact us" sub-link).

You might have better success with the horizontal "inline" code. The beauty of snippets is, you can just bung that code into a new snippet, and call it instead of your original one in your layout. Easy to switch back and forth...

If I've got it wrong, perhaps you could tell us what you are hoping to achieve?

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

9

Re: Submenu with child pages and grandchild pages as imbeded ul's

David, Thank you for your continued help and patience. An example of my end goal is to generate an htlm list that would look like this:

<ul class="secnav">
    <li><a href="#">Current Page</a></li>
    <li><a href="#">Child of Current</a>
        <ul class="subnav">
             <li><a href="#">Child of Child</a></li>
             <li><a href="#">child of child</a></li>
         </ul>
     </li>
      <li><a href="#">Child of current</a>
           <ul class="subnav">
               <li><a href="#">child of child</a></li>
               <li><a href="#">child of child</a></li>
              </ul>
       </li>
</ul>

As far as the structure of the website->Menu goes, hopefully the picture and example below will help explain. The submenu needs to be on any pages that are a child of the homepage, it should essentially treat each page at the same level as "Board" as a home page for each of it's subpages keep it as the first link on the submenu if you were on a child page.

http://i52.tinypic.com/27zlt1d.png

If I could, I'd get the submenu for the board page and all pages nested under the page(Committees, WXCU team, our volunteers, etc) to have a menu like this:

<ul class="secnav">
    <li><a href="./board.html">WXCU Board</a></li>
    <li><a href="#">Our Committies</a>
        <ul class="subnav">
            <li><a href="#">Committie Link</a></li>
            <li><a href="#">Committie Link</a></li>
        </ul>
    </li>
    <li><a href="#">The WXCU Team</a>
        <ul class="subnav">
            <li><a href="#">Committie Memebers</a></li>
            <li><a href="#">Our Volunteers</a></li>
        </ul>
    </li>
</ul>

I'm starting to think that what I'm trying to achieve is too complex for just a snippet?
Thanks again.

Thumbs up

10

Re: Submenu with child pages and grandchild pages as imbeded ul's

d.pock wrote:

I'm starting to think that what I'm trying to achieve is too complex for just a snippet?

There's nothing too complex for a snippet! cool

Try this out:

<!-- THIS CONDITIONAL NAVIGATION COULD GO INTO A SNIPPET / START -->
<?php if ($this->level() > 0) { $parent = reset(explode('/', CURRENT_URI)); $topPage = $this->find($parent); } ?>
<?php if(isset($topPage) && $topPage != '' && $topPage != null) : ?>

<?php if ($this->level() > 0) : ?>
<?php if (count($topPage->children()) > 0 && $topPage->slug() != 'articles') : ?>
<ul class="secnav">
    <li><?php echo $topPage->link($topPage->title, (url_start_with($topPage->url) ? ' class="current"': null)); ?></li>
<?php foreach ($topPage->children() as $subPage): ?>
    <li><?php echo $subPage->link($subPage->title, (url_start_with($subPage->url) ? ' class="current"': null)); ?>
    <?php if (count($subPage->children()) > 0) : ?>
    <ul class="subnav">
        <?php foreach ($subPage->children() as $subSubpage) : ?>
            <li><?php echo $subSubpage->link($subSubpage->title, (url_start_with($subSubpage->url) ? ' class="current"': null)); ?></li>
        <?php endforeach; ?>
    </ul>
    <?php endif; // end child-of-child ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<!-- CONDITIONAL NAVIGATION / END -->

That's based on the conditional navigation in the "default" Wolf layout. As long as you don't go "deeper" than what you show in your screen shot of the page tree, it should work fine.

(Btw: "committee" wink ) Let us know if that works for you!

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

11

Re: Submenu with child pages and grandchild pages as imbeded ul's

Looks like David beat me to it... the following is untested, but should work. (though you'll probably will want to add a loop of some kind for the first level.)

<ul class="secnav">
    <li><?php echo $this->link(); ?></li>
    <?php
    if (Page::hasChildren($this->id())) {
        $children = $this->children();
        foreach ($children as $child) {
            echo '<li>'.$child->link();
            if (Page::hasChildren($child->id())) {
                echo '<ul class="subnav">';
                $subchildren = $child->children();
                foreach ($subchildren as $subchild) {
                    echo '<li>'.$subchild->link().'</li>';
                }
                echo '</ul>';
            }
            echo '</li>';
        }
    }
    ?>
</ul>
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 or see our financial report first.