Based of a snippet I found made by zenmaster (see
this topic) I created this pagination plugin.
installation is very simple:
- create a new plugin
- paste the code
- check the OnLoadWebDocument event
and you are done.
Out of the box:
Installing this plugin will automatically make documents paginated when a
{BREAK} delimiter is detected in the content of the document.
You can ofcourse change the delimiter to anything you prefer and change the template for the pagination.
/*
* Name: Pip (Pagination Plugin)
* Version: 1.0
* Author: Armand "bS" Pondman ([email protected])
* Updated: June 7, 2006 12:00 CET
*
* Description:
* will paginate a document when delimiter is found in the content.
*
* Configuration:
* check the OnLoadWebDocument event
*
* optional:
* Edit the values under the CUSTOMIZE Header
*
*/
## CUSTOMIZE ##
$delimiter = '{BREAK}';
$tplLinkNext = '<a href="[+link+]">Next</a>';
$tplLinkPrev = '<a href="[+link+]">Prev</a>';
$tplLinkNav = '
<div style="margin-top: 10px;font-size: small;">
[+linkprev+]
Page [+current+] of [+total+]
[+linknext+]
</div>';
## DO NOT EDIT BELOW THIS LINE ##
$e = &$modx->Event;
switch($e->name) {
case 'OnLoadWebDocument':
$pip_content = $modx->documentObject['content'];
$pip_pagecontent = explode($delimiter,$pip_content);
$pip_pagecount = count($pip_pagecontent);
if ($pip_pagecount > 1)
{
$pip_currentpage = isset($_GET["page"]) ? $_GET["page"]: 1;
if ($pip_currentpage > $pip_pagecount || $pip_currentpage < 1) { $pip_currentpage = 1; }
$char = ($modx->config['friendly_urls'] == 0) ? "&" : "?";
$url = $modx->makeurl($modx->documentObject["id"],'',$char.'page=');
$prevpage = $pip_currentpage-1;
$nextpage = $pip_currentpage+1;
$linkprev = ($prevpage>0) ? str_replace("[+link+]",$url.$prevpage,$tplLinkPrev) : '';
$linknext = ($nextpage>$pip_pagecount) ? '' : str_replace("[+link+]",$url.$nextpage,$tplLinkNext);
$pip_template = str_replace("[+linkprev+]",$linkprev,$tplLinkNav);
$pip_template = str_replace("[+linknext+]",$linknext,$pip_template);
$pip_template = str_replace("[+total+]",$pip_pagecount,$pip_template);
$pip_template = str_replace("[+current+]",$pip_currentpage,$pip_template);
$pip_content= $pip_pagecontent[$pip_currentpage-1].$pip_template;
}
$modx->documentObject['content'] = $pip_content;
break;
default:
return;
break;
}