我在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'];
}
}
答案 0 :(得分:0)
添加了父页面。现在它也适用于二级页面。
function onStart()
{
$this['search_query'] = get('q', $default = null);
// current page url
$parent = $this->page['apiBag']['staticPage']->getParent();
$url = $this->page['apiBag']['staticPage']['viewBag']['url'];
$currentPage = null;
if($parent) {
$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'];
}
// parent page
$this['parent_title'] = $parent['viewBag']['title'];
$this['parent_url'] = $parent['viewBag']['url'];
}
}
嫩枝:
{% if prev_title|length > 0 %}
<a href="{{ prev_url }}" class="previous">{{ prev_title }}</a>
{% endif%}
{% if parent_title|length > 0 %}
<a href="{{ parent_url }}" class="up">{{ parent_title }}</a>
{% endif%}
{% if next_title|length > 0 %}
<a href="{{ next_url }}" class="next">{{ next_title }}</a>
{% endif%}