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

  • concrete5 Cookbook
  • David Strack
  • 195字
  • 2021-08-13 16:15:59

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.

主站蜘蛛池模板: 新乡市| 游戏| 临夏市| 墨脱县| 花垣县| 叶城县| 宜黄县| 民丰县| 右玉县| 岱山县| 南岸区| 太保市| 长乐市| 嵊泗县| 龙南县| 县级市| 南涧| 鹤壁市| 长寿区| 洛南县| 乌鲁木齐市| 嘉鱼县| 阳西县| 宜都市| 水富县| 成安县| 荃湾区| 莫力| 金溪县| 万安县| 望江县| 肥东县| 长海县| 赤峰市| 琼中| 平利县| 定远县| 青铜峡市| 邛崃市| 延吉市| 曲阳县|