在 Concrete5 中硬编码 page_list 博客
Hardcode page_list blog in Concrete5
之前我已经弄清楚了如何将内容区域和自动导航块硬编码到我的模板中。我正在尝试对显示具有特定页面类型 news entry
的页面的 page_list 执行相同的操作,使用分页并仅显示标题。
这是我得到的结果:
<?php
$archive = BlockType::getByHandle("page_list");
$archive->controller->orderBy = "chrono_desc";
$archive->controller->ctID = "news";
$archive->controller->paginate = true;
$archive->render("view");
?>
但这似乎没有显示网站上的任何页面。我做错了什么?
您似乎在向 ctID 提供页面类型句柄而不是页面类型 ID。
您应该可以这样做:
$sweetPageType = PageType::getByHandle('news');
if(is_object($sweetPageType)) { // let's be extra safe, eh?
$sweetPageTypeID = $sweetPageType->getPageTypeID();
}
然后,在你的硬编码块中(你可以测试你有一个 ID,虽然我认为如果它是 null 它就没有任何效果):
$archive->controller->ctID = $sweetpageTypeID;
不知道您使用的是 5.6 还是 5.7,但我相信两者应该相同。这是 c5 API 的相关 link:
http://concrete5.org/api/class-Concrete.Core.Page.Type.Type.html
之前我已经弄清楚了如何将内容区域和自动导航块硬编码到我的模板中。我正在尝试对显示具有特定页面类型 news entry
的页面的 page_list 执行相同的操作,使用分页并仅显示标题。
这是我得到的结果:
<?php
$archive = BlockType::getByHandle("page_list");
$archive->controller->orderBy = "chrono_desc";
$archive->controller->ctID = "news";
$archive->controller->paginate = true;
$archive->render("view");
?>
但这似乎没有显示网站上的任何页面。我做错了什么?
您似乎在向 ctID 提供页面类型句柄而不是页面类型 ID。
您应该可以这样做:
$sweetPageType = PageType::getByHandle('news');
if(is_object($sweetPageType)) { // let's be extra safe, eh?
$sweetPageTypeID = $sweetPageType->getPageTypeID();
}
然后,在你的硬编码块中(你可以测试你有一个 ID,虽然我认为如果它是 null 它就没有任何效果):
$archive->controller->ctID = $sweetpageTypeID;
不知道您使用的是 5.6 还是 5.7,但我相信两者应该相同。这是 c5 API 的相关 link: http://concrete5.org/api/class-Concrete.Core.Page.Type.Type.html