Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2. /**
  3. * An generic array pager for Drupal.
  4. * For Drupal 5 and 6, the default limit is 10. For Drupal 7 it is 9.
  5. */
  6. function pager_array_splice($data, $limit = 9, $element = 0) {
  7. global $pager_page_array, $pager_total, $pager_total_items;
  8. $page = isset($_GET['page']) ? $_GET['page'] : '';
  9.  
  10. // Convert comma-separated $page to an array, used by other functions.
  11. $pager_page_array = explode(',', $page);
  12.  
  13. // We calculate the total of pages as ceil(items / limit).
  14. $pager_total_items[$element] = count($data);
  15. $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
  16. $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
  17. return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
  18. }
  19. ?>
  20.  
  21.  
  22. $output = '';
  23. $your_array = some_method_to_get_array();
  24. $tree = pager_array_splice($your_array, 5);
  25. // Do something with the 5 terms
  26. $output .= theme('pager', array('quantity' => 5));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement