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

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:

  1. Open /config/site_post.php in your code editor to try out the following code.
  2. Load the page type by its handle.
    $pageType = CollectionType::getByHandle('right_sidebar');
  3. Get the array of Page objects.
    $pages = $pageType->getPages();
  4. 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
主站蜘蛛池模板: 金堂县| 石楼县| 广昌县| 灵丘县| 高邑县| 沙坪坝区| 阿鲁科尔沁旗| 交口县| 玛多县| 南靖县| 惠东县| 朝阳区| 原阳县| 鄂温| 邢台县| 徐汇区| 陆丰市| 博野县| 大石桥市| 邳州市| 新安县| 宝兴县| 富顺县| 长垣县| 醴陵市| 图木舒克市| 寿宁县| 望奎县| 肇州县| 边坝县| 黔西县| 漳平市| 新乐市| 安塞县| 上饶市| 藁城市| 凯里市| 沛县| 道真| 八宿县| 桦甸市|