Display a list of subpages

The ‘status’ of your page will determine how it can be listed. This guide assumes you are looking for “Published” pages. Here is the example of the header snippet:

<ul>
  <li><a href="<?php echo BASE_URL; ?>">home</a></li>
<?php foreach($this->find('/')->children() as $menu): ?>
  <li><?php echo $menu->link(); ?></li>
<?php endforeach; ?>
</ul>

The first LI is added to link the Home Page. BASE_URL is a constant that Frog uses to display the link() or whole URL in the application. You can use it without any problem.

Then you have the $this->find('/') method that will return the page at the URL that you send it to, in this case, the Home Page.

The you have the children() method that will return all subpages of the page already found. (You can do $this->children() and you will get all the “published” and “reviewed” subpages of the current page.)

Then you have a “foreach” loop that will pass each subpage one by one and execute every line between this line and the <?php endforeach; ?>, in this case the line that will be repeated is: <li><?php echo $menu->link(); ?></li>. (There is another page with more information about making links.)

If you take a look at the HTML source code of the page header you will see that the PHP code above has produced something like this:

<ul>
  <li><a href="http://localhost/frog/?">Home</a></li>
  <li><a href="http://localhost/frog/?about_us" title="About us">About us</a></li>
  <li><a href="http://localhost/frog/?articles" title="Articles">Articles</a></li>
</ul>

What else can I do with $this->children()

  1. You can decide to add a condition to the search (be careful with this one!)
  2. You can limit the number of results returned (limit)
  3. You can change the offset to be returned (offset)
  4. You can determine the order (by field name in page table [see note below], either ASC ascending, or DESC descending)
  5. That’s enough power I think!

Example 1:
if you want to display the last 5 results only, here is how to do it:

<?php $last_result = $this->children(array('limit' => 5, 'order' => 'created_on DESC')); ?>

Then you need to loop those results like the example in the previous HOW-TO.

Example 2:
if you only want results 3 and 4, ordered by the position (by default):

<?php $last_result = $this->children(array('offset' => 2, 'limit' => 2)); ?>

This might appear weird to you but … the offset starts at 0 not at 1.

A note on “order”
Any of the fields in the page table can be used to sort your “children” pages. In Example 1, above, you could have:

'order' => 'title ASC'

to arrange the order by the page Title in A-Z order, or

'order' => 'slug DESC'

to order the list by “slug” value in Z-A order. That should give you the idea! While any value in the “page” table could be used here, the main options would include:

  • title
  • slug
  • breadcrumb
  • created_on
  • published_on
  • updated_on
  • created_by_id
  • updated_by_id

The default is position, which is set automatically when the drag-drop page re-ordering is used.


Frog CMS Demo

Public front end website click here
Administration backend click here

Opensource.com admin login info:
login: admin
password: demo123

Help us!

There is no profit here. The more we raise the longer we can keep things going and the better it will get.

Click here to lend your support to: Frog CMS and make a donation at www.pledgie.com !







Book online: Private tours Spain, visit our wonderful country. | Visit mightystudents.com/ for premium quality essays from our writers. | На интернет-проекте этой конторы секс шоп - заходите.