Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * An generic array pager for Drupal.
- * For Drupal 5 and 6, the default limit is 10. For Drupal 7 it is 9.
- */
- function pager_array_splice($data, $limit = 9, $element = 0) {
- global $pager_page_array, $pager_total, $pager_total_items;
- $page = isset($_GET['page']) ? $_GET['page'] : '';
- // Convert comma-separated $page to an array, used by other functions.
- $pager_page_array = explode(',', $page);
- // We calculate the total of pages as ceil(items / limit).
- $pager_total_items[$element] = count($data);
- $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
- $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
- return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
- }
- ?>
- $output = '';
- $your_array = some_method_to_get_array();
- $tree = pager_array_splice($your_array, 5);
- // Do something with the 5 terms
- $output .= theme('pager', array('quantity' => 5));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement