【发布时间】:2017-07-06 10:32:32
【问题描述】:
我在october cms(静态页面插件)的后端有这样的结构
Page
-subpage 1
-subpage 2
-subpage 3
我希望能够在子页面之间链接以转到下一个和上一个(如果存在)。
找不到任何关于此的内容。
好的。这就是我所拥有的 - 不是最优雅的解决方案,但它有效 在子页面的代码部分! (这应该是检查页面是否有父页面,但在我的情况下,我只使用指向子页面的链接)
function onStart(){
// current page url
$parent = $this->page['apiBag']['staticPage']->getParent();
$url = $this->page['apiBag']['staticPage']['viewBag']['url'];
$currentPage = null;
$children = $parent->getChildren();
foreach( $children as $key => $page){
if($page['viewBag']['url'] == $url) $currentPage = $key;
}
// previous page
if ( array_key_exists($currentPage - 1, $children) ) {
$this['prev_url'] = $children[$currentPage - 1]['viewBag']['url'];
$this['prev_title'] = $children[$currentPage -1 ]['viewBag']['title'];
}
if ( array_key_exists($currentPage + 1, $children) ) {
$this['next_url'] = $children[$currentPage + 1]['viewBag']['url'];
$this['next_title'] = $children[$currentPage + 1]['viewBag']['title'];
}
}
【问题讨论】:
-
好吧 .. 那你为什么不创建自己的博客类型的插件 .. 在其中添加记录并通过查询下一个和上一个链接来检查 ..
标签: php laravel octobercms octobercms-plugins