-
-
Save bugsysop/9263912 to your computer and use it in GitHub Desktop.
Template for Kirby CMS that splits long post into several pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Source and documentation : http://www.texniq.de/en/kirby-wiki/split-long-posts-into-pages | |
// store the content of the kirbytext text variable in $text | |
$text = kirbytext($page->text()); | |
// split the content of $text whenever a <!--pagebreak--> code is encountered and store in the array $pages | |
$pages = explode('<!--pagebreak-->', $text); | |
// count the number of pages in the array | |
$pageCount = count ($pages); | |
//set pageLinkCount | |
if($pageCount >= 1) : $pageLinkCount = 1; | |
else : $pageLinkCount = 0; | |
endif; | |
// create a new page object | |
$pages = new Pages($pages); | |
// paginate the page object at every page | |
$pages= $pages->paginate(1); | |
//create a new page for each item in $pages | |
foreach ($pages as $p): | |
snippet('header') ?> | |
<article> | |
<h1><?= $page->title()?><? if (! $firstPage): echo " - Part ".$pages->pagination()->page(); endif ?></h1> | |
<?php echo $p?> | |
//create the page navigation (prev, pagenumbers, next) | |
<?php | |
if($pages->pagination()->hasPrevPage()):?> | |
<nav> | |
<a class="next" href="<?php echo $pages->pagination()->prevPageURL()?>">Prev</a> | |
<?php endif; | |
while($pageLinkCount <= $pageCount && $pageCount > 1) : ?> | |
<a <?= ($pageLinkCount == ($pages->pagination()->page()))?' class="active"':''?> href="<?php echo $pages->pagination()->pageURL($pageLinkCount) ?>"><?php echo $pageLinkCount ?></a> | |
<?php $pageLinkCount++; | |
endwhile ?> | |
<?php if($pages->pagination()->hasNextPage()):?> | |
<a class="prev" href="<?php echo $pages->pagination()->nextPageURL()?>">Next</a> | |
</nav> | |
<?php endif?> | |
</article> | |
</main> | |
<?php snippet('footer')?> | |
<?php endforeach ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment