Topic: Display children pages in menu?

Greetings again,

Was  a while since I last visited the forum. I am trying to figure out how to display a second menu inside a parent page.
For example lets take this page -

http://monstra.org/about

About is parent to children -
    Testimonials
    License
    Logos and Graphics

But what if I have like 20 children pages...must be a simple way of using some php magic to create the menu dynamically?
I tried

<?php $pages = Page::children('page'); ?>
<?php foreach($pages as $page) { ?>
    <a href="<?php echo Site::url().'myparentpage/'.$page['slug']; ?>"><?php echo $page['title']; ?></a>
<?php } ?>

but it doesn't work...why?

Re: Display children pages in menu?

Change the name of Page::children('page')

<?php $pages = Page::children('myparentpage'); ?>
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Display children pages in menu?

Nakome you are the man!
Thank you!

4 (edited by RedStar 2013-02-26 07:49:46)

Re: Display children pages in menu?

Hmmm....which leads to my next question...
What if you have 10 parents? This code works only for 1 parent. So my guess is we need some conditional statements like if/else or Switch/case?
So my idea is to add a snippet inside template

<?php echo Snippet::get('submenus'); ?>

and then
add conditional code inside the snippet.
Am I thinking correct?

Are there any code example on this?

5 (edited by nakome 2013-02-26 11:42:18)

Re: Display children pages in menu?

Maybe you must use  menu::get('category') is easier, The conditional statements only get a single menu

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Display children pages in menu?

looking through the page.plugin code...

echo Page::available();

is this the one you want??
but as i understood, it's without sorting at the time...

anyway, have a look here

Re: Display children pages in menu?

antiben wrote:

looking through the page.plugin code...

echo Page::available();

is this the one you want??
but as i understood, it's without sorting at the time...

anyway, have a look here

Yes that is exactly what I was looking for. A big thanks for help! But only problem I see is that all child pages are displayed
even though some child pages has status = draft.
Do you have an idea how to fix this?

Once again a big thank you!

Think to be able to use monstra to its fully potential you need to be able to know some php, a skill that I moment in time
lack.

8 (edited by antiben 2013-03-07 00:09:12)

Re: Display children pages in menu?

this small 'Page::available()' func. (nor the org. template below) doesn't use the page fields: 'status' and 'access'

you may have to add some mods...
for instance the template at plugins/box/pages/views/frontend/available_pages.view.php

<ul>
<?php
  foreach ($pages as $page) {
    if ($page['status'] == 'published') {
?>
    <li><a href="<?php echo $page['parent'].'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a></li>
<?php
    }
  }
?>
</ul>

9 (edited by RedStar 2013-03-11 02:13:01)

Re: Display children pages in menu?

antiben wrote:

this small 'Page::available()' func. (nor the org. template below) doesn't use the page fields: 'status' and 'access'

you may have to add some mods...
for instance the template at plugins/box/pages/views/frontend/available_pages.view.php

<ul>
<?php
  foreach ($pages as $page) {
    if ($page['status'] == 'published') {
?>
    <li><a href="<?php echo $page['parent'].'/'.$page['slug']; ?>"><?php echo $page['title']; ?></a></li>
<?php
    }
  }
?>
</ul>

Antiben you are a Monstar! smile
Sorry for my late reply but I have kids and only time I can get some peace and quiet is during Dracula hours.
Does this mean there is a bug in code since by default drafted pages are displayed? Maybe need to report...
Problem now is when entering a subpage the menu disapears sad
Does your snippet solve this ?
Once again a big thank you!

Awilum how did you make the Parent/child menus on http://monstra.org/documentation/installation or maybe a secret ??? smile

Re: Display children pages in menu?

Awilum how did you make the Parent/child menus on http://monstra.org/documentation/installation or maybe a secret ???

http://monstra.org/contribute

<li class="nav-header">Contribute</li>
<li <?php if (Uri::segment(1) == 'donate') echo 'class="active"'; ?>><a href="<?php echo Site::url(); ?>contribute/donate">Donate</a></li>
<li <?php if (Uri::segment(1)  == 'sponsors') echo 'class="active"'; ?>><a href="<?php echo Site::url(); ?>contribute/sponsors">Sponsors</a></li>
Monstra Loves You! Give some love back!

11 (edited by RedStar 2013-03-12 01:21:09)

Re: Display children pages in menu?

Awilum I will sponsor your project no worries. smile

Btw I just found out that I used wrong version of monstra and trying to get the menus to work...lol