Difference between revisions of "Functions:pagination"
From Whirlwind eCommerce Wiki
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | {{Page Template Functions Shortcuts}} | ||
== Description == | == Description == | ||
pagination() returns data and content to easily 'paginate' large data lists | pagination() returns data and content to easily 'paginate' large data lists | ||
Line 46: | Line 47: | ||
== Examples == | == Examples == | ||
− | ; | + | ;Page Children Example |
− | example 1 | + | <source lang="php"> |
+ | |||
+ | // pageNo variable to hold the number of the current pagination page we are in | ||
+ | // defaulting to page 1 | ||
+ | if(!isset($attributes['pageNo'])) $attributes['pageNo'] = 1; | ||
+ | |||
+ | // lets get our children | ||
+ | $children = eV::pageChildrenGet($pageId,'title,link'); | ||
+ | |||
+ | // lets paginate the children | ||
+ | // using 10 items per page for this example | ||
+ | // link set to reload this exact page | ||
+ | $pagination = eV::pagination(count($children),10,$attributes['pageNo'],'index.php?pageId=$pageId'); | ||
+ | |||
+ | // output the summary of where we are | ||
+ | echo "<hr>Showing item(s) " . ($pagination['startIndex'] +1) . " through " . ($pagination['endIndex']+1) . " of " . count($children); | ||
+ | |||
+ | // output the pagination navigation links | ||
+ | // this echo will automatically display the "<previous 1 2 3 4 next>" links for pagination navigation | ||
+ | echo $pagination['links']; | ||
+ | |||
+ | // now lets display the qualifying items in this page | ||
+ | // use the startIndex and endIndex elements to hide/show the appropriate items | ||
+ | // using a counter to track which child we are on in the loop for comparison | ||
+ | $counter = 0; | ||
+ | foreach($children as $child){ | ||
+ | // only display child if it's index is between startIndex and endIndex | ||
+ | if($counter >= $pagination['startIndex'] && $counter <= $pagination['endIndex']){ | ||
+ | echo "<br><a href=\"" . $child['link'] . "\">" . $child['title'] . "</a>"; | ||
+ | }; | ||
+ | $counter++; | ||
+ | }; | ||
+ | |||
+ | </source> | ||
;example 2 | ;example 2 | ||
example 2 goes here | example 2 goes here | ||
== See Also == | == See Also == | ||
− | :*[[ | + | :*[[Functions:pageChildrenGet]] |
− | :*[[ | + | :*[[Functions:pageSearchGet]] |
− | + |
Latest revision as of 20:58, 3 December 2008
Description
pagination() returns data and content to easily 'paginate' large data lists
Syntax
$pagination = eV::pagination($totalCount,$itemsPerPage,$pageNo,$link);
Paramaters
- $totalCount
- total number of items in the entire list to be paginated
- $itemsPerPage
- number of items to display on each pagination page
- $pageNo
- the current page number
- $link
- the base url to be used for each pagination link. This will automatically be appended with "&pageNo=#" for the appropriate page number for the link selected.
Return Values
Returns an associative array containing content output and list item indexes to be used to manage pagination. Below is the returned array:
Array ( [links] => String [startIndex] => INT [endIndex] => INT )
Elements from the returned array are as follows:
Element | Description | Example |
links | STRING - HTML output including previous, next and page number links. Just echo this data where you want the pagination controls to appear to the visitor | <a href="index.php?pageId=10&pageNo=1">< PREVIOUS</a> <a href="index.php?pageId=10&pageNo=1">1</a> 2 <a href="index.php?pageId=10&pageNo=3">3</a> <a href="index.php?pageId=10&pageNo=4">4</a> <a href="index.php?pageId=10&pageNo=3">< NEXT</a> |
startIndex | INT - the index of the first list element that should appear in the page (hide all elements before this) | 6 |
endIndex | INT - the index of the last list element that should appear in the page (hide all elements after this) | 10 |
Examples
- Page Children Example
// pageNo variable to hold the number of the current pagination page we are in // defaulting to page 1 if(!isset($attributes['pageNo'])) $attributes['pageNo'] = 1; // lets get our children $children = eV::pageChildrenGet($pageId,'title,link'); // lets paginate the children // using 10 items per page for this example // link set to reload this exact page $pagination = eV::pagination(count($children),10,$attributes['pageNo'],'index.php?pageId=$pageId'); // output the summary of where we are echo "<hr>Showing item(s) " . ($pagination['startIndex'] +1) . " through " . ($pagination['endIndex']+1) . " of " . count($children); // output the pagination navigation links // this echo will automatically display the "<previous 1 2 3 4 next>" links for pagination navigation echo $pagination['links']; // now lets display the qualifying items in this page // use the startIndex and endIndex elements to hide/show the appropriate items // using a counter to track which child we are on in the loop for comparison $counter = 0; foreach($children as $child){ // only display child if it's index is between startIndex and endIndex if($counter >= $pagination['startIndex'] && $counter <= $pagination['endIndex']){ echo "<br><a href=\"" . $child['link'] . "\">" . $child['title'] . "</a>"; }; $counter++; };
- example 2
example 2 goes here