Page Extension Version 3.2.0
Pages’ part indicator is now more accurate.
The pages’ part indicator is now more accurate. This allows you to display both “item” and “items” view by simply adding/removing the pages’ part indicator from the URL:
Path | Response |
---|---|
/article | This will display the “item” view of .\lot\page\article.archive or .\lot\page\article.page file. |
/article/1 | This will display the “items” view of .\lot\page\article.archive or .\lot\page\article.page file. If it does not have any page children yet, this will display the error 404 state of the “item” view. |
/article/0 | This will display the error 404 state of the “item” view. Valid pages’ part indicator must be an integer greater than 0 . The 0 part here is treated as a file name. |
/article/+1 | The +1 part here is treated as a file name, so this will display the error 404 state of the “item” view if you do not have a valid .\lot\page\article\+1.archive or .\lot\page\article\+1.page file. |
/article/-1 | The -1 part here is treated as a file name, so this will display the error 404 state of the “item” view if you do not have a valid .\lot\page\article\-1.archive or .\lot\page\article\-1.page file. |
A new Page::children()
method has been added to return the children of the current page as Pages
instances. But unlike the $pages
variable, the result is simply a list of all children of the current page in no particular order. You will need to query it yourself to get the desired results:
<h3>
<?= i('Random %s', 'Pages'); ?>
</h3>
<?php if ($page->children && $page->children->count > 0): ?>
<ul>
<?php foreach ($page->children->shake->chunk(10, 0) as $v): ?>
<li>
<a href="<?= eat($v->url); ?>">
<?= $v->title; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p role="status">
<?= i('No %s yet.', 'pages'); ?>
</p>
<?php endif; ?>
You may need to modify the existing site navigation layout to conditionally add the pages’ part to the navigation link to those that have children, so that clicking the Article link in the navigation will display the Article page’s “items” view instead of the Article page’s “item” view:
<nav>
<ul>
<li>
<?php if ($site->is('home')): ?>
<a aria-current="page">
<?= i('Home'); ?>
</a>
<?php else: ?>
<a href="<?= eat($url); ?>">
<?= i('Home'); ?>
</a>
<?php endif; ?>
</li>
<?php foreach ($links as $link): ?>
<li>
<a<?= $link->current ? ' aria-current="page"' : ""; ?> href="<?= eat($link->link ?: ($link->url . ($link->children && $link->children->count > 0 ? '/1' : ""))); ?>">
<?= $link->title; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</nav>
You may also need to modify your existing $pages
loop, just in case you have a page URL somewhere that should point the reader to the multiple page view instead of the single page view:
<?php foreach ($pages as $page): ?>
<article>
<h3>
<?php if ($link = $page->link): ?>
<a href="<?= eat($link); ?>" rel="nofollow" target="_blank">
<?= $page->title; ?>
</a>
<?php else: ?>
<a href="<?= eat($page->url . ($page->children && $page->children->count > 0 ? '/1': "")); ?>">
<?= $page->title; ?>
</a>
<?php endif; ?>
</h3>
<p>
<?= $page->description; ?>
</p>
</article>
<?php endforeach; ?>
Another option is to provide a link at the bottom of the page that will take the reader to the multiple page view:
<h2>
<?= $page->title; ?>
</h2>
<?= $page->content; ?>
<?php if ($page->children && $page->children->count > 0): ?>
<p>
<a href="<?= eat($page->url . '/1'); ?>">
<?= i('Browse pages...'); ?>
</a>
</p>
<?php endif; ?>
0 Comments
No comments yet.