Получить ссылку на следующую и предыдущую подстраницы на страницах October CMS Plugin

У меня есть такая структура в бэкэнде 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'];
  }

}

person adam    schedule 06.07.2017    source источник
comment
Ну .. тогда почему бы вам не создать свой собственный плагин для блога .. в который вы будете добавлять свои записи и проверять, запрашивая следующую и предыдущую ссылки ..   -  person Mittul At TechnoBrave    schedule 07.07.2017


Ответы (1)


Добавлена ​​родительская страница. Также теперь это работает для страниц второго уровня.

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%}
person zooks    schedule 05.10.2017