官术网_书友最值得收藏!

Getting the children below a page

If you need to access the children of a page, you can have concrete5 return an array of numerical IDs. These IDs can then be used to load each of the Page objects individually.

How to do it...

The steps for getting the children below a page are as follows:

  1. Open /config/site_post.php in your preferred code editor.
  2. Load the parent page by its ID.
    $page = Page::getByID(1);
  3. Get the array of child IDs.
    $children = $page->getCollectionChildrenArray();
  4. Loop through the child ID array and output the name of each page.
    foreach ($children as $childId) {
      $child = Page::getByID($childId);
      echo $child->getCollectionName().'<br />';
    }
  5. Exit the process.
    exit;

How it works...

concrete5 will return an array of numeric IDs for each of the pages beneath the parent page. In this example, we loaded the home page, so the result should be a list of every page on the website. This function ignores permissions, and can be taxing on the database if there are a lot of pages to load. It is a better idea to use the PageList class to loop through pages, and that class is described later on in this chapter.

主站蜘蛛池模板: 桑植县| 新营市| 无锡市| 行唐县| 黄梅县| 彰化市| 景德镇市| 稻城县| 张家港市| 壤塘县| 西乌| 黄浦区| 定结县| 沐川县| 曲水县| 金平| 陈巴尔虎旗| 中西区| 邯郸市| 巴林左旗| 化州市| 永城市| 竹山县| 新沂市| 西藏| 靖西县| 石台县| 卢龙县| 平阳县| 洛浦县| 霍林郭勒市| 乌海市| 江川县| 安吉县| 彰化市| 福州市| 龙陵县| 平阴县| 达州市| 兴和县| 佳木斯市|