Search code examples
phpcontent-management-systemconcrete5

Hardcode page_list blog in Concrete5


Previously I've worked out how to hardcode content areas and the autonav block into my templates. I'm trying to do the same for a page_list which displays pages with a certain page type news entry, using pagination and just showing the title.

Here's how far I got:

<?php
  $archive = BlockType::getByHandle("page_list");
  $archive->controller->orderBy = "chrono_desc";
  $archive->controller->ctID = "news";
  $archive->controller->paginate = true;
  $archive->render("view");
?>

But this doesn't seem to display any pages on the site. What have I done wrong?


Solution

  • It looks like you're supplying a page type handle instead of an page type ID to ctID.

    You should be able to do something like so:

    $sweetPageType = PageType::getByHandle('news');
    if(is_object($sweetPageType)) { // let's be extra safe, eh?
          $sweetPageTypeID = $sweetPageType->getPageTypeID();
    }
    

    And then, in your hardcoded block (you could test that you have an ID, although I think if it's null it would just have no effect):

    $archive->controller->ctID = $sweetpageTypeID;
    

    Dunno if you're using 5.6 or 5.7 but I believe it should be the same for both. Here's a relevant link to the c5 API: http://concrete5.org/api/class-Concrete.Core.Page.Type.Type.html