- 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.
推薦閱讀
- 軟件安全技術(shù)
- Learn Blockchain Programming with JavaScript
- Web交互界面設(shè)計(jì)與制作(微課版)
- C語言程序設(shè)計(jì)教程(第2版)
- HTML5+CSS3基礎(chǔ)開發(fā)教程(第2版)
- SQL for Data Analytics
- Learn Programming in Python with Cody Jackson
- Java應(yīng)用開發(fā)技術(shù)實(shí)例教程
- Mastering Unity 2D Game Development(Second Edition)
- Android Development Tools for Eclipse
- Flask開發(fā)Web搜索引擎入門與實(shí)戰(zhàn)
- C語言從入門到精通(視頻實(shí)戰(zhàn)版)
- PHP 7 Programming Blueprints
- Learning Apache Thrift
- Neo4j權(quán)威指南 (圖數(shù)據(jù)庫技術(shù)叢書)