- 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:
- Open
/config/site_post.php
in your preferred code editor. - Load the parent page by its ID.
$page = Page::getByID(1);
- Get the array of child IDs.
$children = $page->getCollectionChildrenArray();
- 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 />'; }
- 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.
推薦閱讀
- 自己動手寫搜索引擎
- C和C++安全編碼(原書第2版)
- JavaScript+jQuery開發實戰
- Python零基礎快樂學習之旅(K12實戰訓練)
- Wireshark Network Security
- The Computer Vision Workshop
- Mastering KnockoutJS
- Oracle從入門到精通(第5版)
- Scala編程實戰(原書第2版)
- 運用后端技術處理業務邏輯(藍橋杯軟件大賽培訓教材-Java方向)
- Bootstrap for Rails
- SQL Server 2008中文版項目教程(第3版)
- 分布式架構原理與實踐
- Java高手是怎樣煉成的:原理、方法與實踐
- Go語言編程之旅:一起用Go做項目