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

Show sub-pages excerpt at parent page?

Feed 10 posts, 3 voices

Avatar
17 posts

Can’t find it anywhere at forum.

I need to show excerpts from sub-pages at parent page. Basically I want to make page looks like Articles.

I have:

#Main_Page
—Sub_page
—Sub_page
—Sub_page

So I want show all Sub_pages at Main_page.

Can anyone give me opinion how can I do it?

Thank you!

 
Avatar
1493 posts

Try putting this code on Main_Page, zigmat:

<?php

  foreach ($this->children(array('order' => 'title ASC')) as $child): ?>

  <h3><?php echo $child->link(); ?></h3>

  <?php echo $child->content(); ?>
  <?php if ($child->hasContent('extended')) echo $child->link('Continue Reading…'); ?>

  <p><strong>Tags</strong>: <?php echo join(', ', $child->tags()); ?></p>
  <p class="info">Posted by <?php echo $child->author(); ?> on <?php echo $child->date(); ?></p>

<?php endforeach; ?>

Adjust the style/layout as you wish. (I put in most things thinking it would be easier to take them out than to add them in.) That will sort the pages alphabetically by title. If you simply want them in the order they were created, then change this line:

 foreach ($this->children(array('order' => 'title ASC')) as $child): ?>

to read like this:

 foreach ($this->children(array('order' => 'created_on ASC')) as $child): ?>

You can find a lot more about this in the docs on listing pages, or in the navigation guide.

 
Avatar
3 posts

Also, you can just remove

array('order' => 'title ASC')

from the children method to use the order from the Admin page, if you want them in an arbitrary order.

 
Avatar
17 posts

Ok. Thank you! It’s works great.

But I have one more.

#Main_Page
—Sub_page_1
——Sub_sub_page
——Sub_sub_page
——Sub_sub_page
—Sub_page_2
——Sub_sub_page
—Sub_page_3
——Sub_sub_page

So I need show all Sub_sub_pages at Main_page without showing there Sub_pages.

I think it need to be something like this | foreach ($this->find(’/Sub_page_1/,/Sub_page_2/,/etc/’)->children(array(‘order’ => ‘title ASC’)) as $child): ?> |

But this doesn’t seems to work.

 
Avatar
1493 posts

You could use this on “Main_Page”:

<?php
function nav_sitemap($parent)
{
    $out = '';
    $childs = $parent->children();
    if (count($childs) > 0)
    {
        $out = '<ul>';
        foreach ($childs as $child)
            $out .= '<li>'.$child->link().nav_sitemap($child).'</li>';
        $out.= '</ul>';
    }
    return $out;
}
?>

<div>
<ul>
<li><?php echo $this->link(); ?>
<?php echo nav_sitemap($this->find($this->slug)); ?>
</li>
</ul>
</div>

If you don’t need “Main_Page” in the list, then take out everything except the <?php echo nav_sitemap... line in the DIV at the end.

There is a lot like this you can find in the navigation guide!

 
Avatar
17 posts

No, you give me some navigation (sitemap), I know how to do that it is simple.

What I need is to fetch all Sub_sub_pages and view them on #Main_Page like content or excerpt.

Your first example is what something what I need. But I need to show on #Main_Page all Sub_sub_pages content like Title, content (excerpt), tags and etc, without viewing there Sub_pages.

 
Avatar
17 posts

I think it can be something like this:

<?php 

  foreach ($this->find('/Sub_page/')->children(array('order' => 'title ASC') as $child): ?>

  <h3><?php echo $child->link(); ?></h3>

  <?php echo $child->content(); ?>
  <?php if ($child->hasContent('extended')) echo $child->link('Continue Reading…'); ?>

  <p><strong>Tags</strong>: <?php echo join(', ', $child->tags()); ?></p>
  <p class="info">Posted by <?php echo $child->author(); ?> on <?php echo $child->date(); ?></p>

<?php endforeach; ?>

But this code not work but if it worked anyway it will show only childrens from one of the Sun_pages.

P.S. Sorry I didn’t get how to format code with bc., and normal <code></code> doesn’t work.

 
Avatar
17 posts

Yotaa! Something is working :)

<?php foreach ($this->find('/portfolio/web/')->children() as $child): ?>

  <h3><?php echo $child->link(); ?></h3>

  <?php echo $child->content(); ?>
  <?php if ($child->hasContent('extended')) echo $child->link('Continue Reading…'); ?>

  <p><strong>Tags</strong>: <?php echo join(', ', $child->tags()); ?></p>
  <p class="info">Posted by <?php echo $child->author(); ?> on <?php echo $child->date(); ?></p>

<?php endforeach; ?>

It’s working, but when I’m trying to sort it and adding in children() this array(‘order’ => ‘title ASC’) it’s stop working.

What the problem?

And how to add more than one search in find(’‘)?

 
Avatar
17 posts

So I will tell you what I want to do and will be glad if you will help me. In Wordpress and ModX it was simple.

I have:

#Portfolio:
—Web
——Eiderdown
——Private Villa
—Graphic Design

I want to take all subpages from Web and Graphic Design and show them at Portfolio.

In Eiderdown and Private Villa I want to add custom field (tab) and add there thumbmail picture. It should look something like this – LINK

But after all my work it looks like this – LINK

I figure out how to fetch data from specific subpage and etc.

But i don’t understand how to show image from tab.

Any opinion?

 
Avatar
17 posts

Please, some one…

 
Avatar
3 posts

You should just be able to add a line like this:

 <?php if ($child->hasContent('tab')) echo $child->content('tab'); ?>

Assuming the tab has a fully formed <img> tag.