I've hit a bit of a brick wall here, so would appreciate some insight (if someone could oblige).
I've set this up so that the main blog page displays an initial 3 posts when loaded fully.
On clicking a "more posts" button underneath the 3 posts that are displayed, infinite scroll pagination (which has been set-up) kicks in but...I only want
2 posts (or 4, 5 etc.) at a time to be served
not 3 thereafter.
Can anyone help, it's probably obvious
Hope this makes sense.
<?php
$method = $modx->getOption('method', $scriptProperties, 'initial');
$limit = $modx->getOption('limit', $scriptProperties, 3);
$parent = $modx->getOption('parent', $scriptProperties);
$tpl = $modx->getOption('tpl', $scriptProperties);
$tplFirst = $modx->getOption('tplFirst', $scriptProperties);
$load = (int) $_GET['page'];
$offset = 0;
if($method == "initial") {
if($load != 0) {
$limit = $limit * $load;
}
} elseif($method == "pagination") {
$offset = $limit * ($load - 1);
}
$page = $modx->runSnippet('getResources', array(
'parents' => $parent,
'limit' => $limit,
'offset' => $offset,
'includeTVs' => '1',
'tvPrefix' => '',
'includeContent' => '1',
'tpl' => $tpl,
'tplFirst' => $tplFirst
));
if($method == "initial") {
return $page;
} elseif($method == "pagination") {
if(empty($page)) {
$noResults = $modx->parseChunk('pagination-no-results',array('text' => 'No more posts!'));
return json_encode(array(
'success' => false,
'page' => $noResults
));
} else {
return json_encode(array(
'success' => true,
'page' => $page
));
}
}