-
MODX Staff
- 12,272 Posts
Hi mmjaeger,
Out of curiosity, where did the snippet come from, and what is it supposed to do? I’ll take a look at it very soon.
Thanks!
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
-
☆ A M B ☆
- 24,524 Posts
Sorry, I should have put the whole snippet here - the listing of the news works - what’s causing troubles is the paginator at the bottom - the results produces are just not accurate - it e.g. show that there are four pages when in fact there are only three. Moreover, the page indication should be hidden if there is only one page.
/*****************************************************************
* NewsIndex
* Created by: Wayne Chu
* wayne at freethought dot ca
* Sep 2, 2004
*
* Description:
* Displays a paginated list of items in
* the specified folder.
*
* Usage: [[NewsIndex?newsid={id}&desc={true|false}&sep={string}&pub=1]]
* Variables: newsid - the ID of the folder to retrieve items from
* desc - Optional boolean indicating if the page
* description should be displayed
* sep - Optional variable defining the separating
* string between the date and the title
* pub - Optional variable defining whether to publish
* unpublished items (1 = published, 0 = unpublished)
*
****************************************************************/
$itemsPerPage = 5;
$itemCss = "newslistitem";
$itemCssDate = "newslistdate";
$itemCssTitle = "newslisttitle";
$itemCssPaging = "newslistpaging";
$itemCssDescription = "newslistdesc";
$separator = "
";
//$dateFormat = "%F %j, %Y";
setlocale (LC_TIME,"de_DE");
$dateFormat = "%A, %e. %B %Y";
if (isset($sep))
$separator = $sep;
// News Folder
$id = isset($newsid) ? $newsid : $etomite->documentIdentifier;
// Current Page
$currPage = isset($_GET[’page’]) ? $_GET[’page’] : 1;
// News Folder
$folder = isset($newsid) ? $newsid : $etomite->documentIdentifier;
// Current Page
$currPage = isset($_GET[’page’]) ? $_GET[’page’] : 1;
$items = $etomite->getAllChildren($folder, ’createdon’, ’DESC’, $fields=’id, pagetitle, description, content, createdon, createdby’);
$totalItems = count($items);
if ($totalItems < 1)
return;
$totalPages = (int)($totalItems / $itemsPerPage);
if ($totalItems % $currPage > 0)
$totalPages++;
if ($currPage < 1 || $currPage > $totalPages)
$currPage = 1;
$firstItem = ($currPage * $itemsPerPage) - $itemsPerPage;
$lastItem = ($currPage * $itemsPerPage);
if ($lastItem > $totalItems)
$lastItem = $totalItems;
$output = "";
// Display news items
for ($i=$firstItem; $i<$lastItem; $i++) {
$output .= "<div class=’" . $itemCss . "’>";
$output .= "<span class=’" . $itemCssDate . "’>" . strftime($dateFormat, $items[$i][’createdon’]) . "</span>";
$output .= "<span class=’" . $itemCssTitle . "’>";
$output .= "<a href=’[~" . $items[$i][’id’] . "~]’>" . $items[$i][’pagetitle’] . "</a>";
$output .= "</span>";
$output .= "</div>";
if (isset($desc) && $desc == true)
$output .= "<div class=’" . $itemCssDescription . "’>" . $items[$i][’description’] . "</div>";
$output .= $separator;
}
// Display Pagination
$paginationGroup = (int)(($currPage-1) / 10);
$firstDisplayPage = ($paginationGroup * 10) + 1;
$lastDisplayPage = ($paginationGroup * 10) + 10;
if ($lastDisplayPage > $totalPages)
$lastDisplayPage = $totalPages;
$output .= "<div class=’" . $itemCssPaging . "’>[ ";
if ($totalItems < $itemsPerPage) {
$output .= " <strong>1</strong> ";
} else {
if ($firstDisplayPage > 1)
$output .= " <a href=’[~" . $etomite->documentIdentifier . "~]&page=" . ($firstDisplayPage-1) . "’>...</a> ";
for ($j=$firstDisplayPage; $j<=$lastDisplayPage; $j++) {
if ($j == $currPage)
$output .= " <strong>" . $j . "</strong> ";
else
$output .= " <a href=’[~" . $etomite->documentIdentifier . "~]&page=" . $j . "’>" . $j . "</a> ";
}
if ($lastDisplayPage < $totalPages)
$output .= " <a href=’[~" . $etomite->documentIdentifier . "~]&page=" . $j . "’>...</a> ";
}
$output .=" ]</div>";
return $output;