- concrete5 Cookbook
- David Strack
- 233字
- 2021-08-13 16:15:56
Getting a list of pages that belong to a page type
In many advanced concrete5 applications, developers may need to find a list of all of the pages that belong to a given page type. In this example, we will get an array of pages that have a page type with the handle of right_sidebar
.
Getting ready
If your instance of concrete5 does not have a page type with the handle of right_sidebar
, feel free to adapt the recipe to suit your needs. We will continue using /config/site_post.php
as our sandbox to run random code snippets, as well as our custom debugging function that we created in this chapter's introduction.
How to do it...
The steps for getting a list of pages belonging to a page type are as follows:
- Open
/config/site_post.php
in your code editor to try out the following code. - Load the page type by its handle.
$pageType = CollectionType::getByHandle('right_sidebar');
- Get the array of
Page
objects.$pages = $pageType->getPages();
- Dump the array to see its contents.
foreach ($pages as $page) { echo $page->getCollectionTitle().'<br />'; } exit;
How it works...
concrete5 simply uses the relational MySQL database to find all of the pages that are related to the page type. Be aware that concrete5 ignores permissions settings when this function is called, so this should really only be used for internal purposes.
See also
- The Getting a page type by its handle recipe
- Instant Testing with CasperJS
- Beginning Java Data Structures and Algorithms
- Python爬蟲開發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Learning Apache Kafka(Second Edition)
- PHP 7+MySQL 8動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Java 從入門到項(xiàng)目實(shí)踐(超值版)
- Visual Basic程序設(shè)計(jì)基礎(chǔ)
- Building a Media Center with Raspberry Pi
- Android 5從入門到精通
- Swift Essentials(Second Edition)
- R語(yǔ)言與網(wǎng)站分析
- Python編程:從入門到實(shí)踐(第2版)
- JavaScript前端開發(fā)程序設(shè)計(jì)教程(微課版)
- Ionic Framework By Example
- C語(yǔ)言從入門到精通(第4版)