Sunday, June 9, 2013

Custom Pagination for Item_list - Drupal 7

For theme item_list function, pagination is tricky in Drupal 7. It's not straight forward, we need to use couple of methods to achieve it, one is use of pager_default_initialize and the other is use of sliced array to theme item list function. Below is a sample code to achieve it:

$items = array('Sports', 'Business', 'Entertainment', 'Politics');
$limit = 3;
$page = pager_default_initialize(count($items), $limit);
$offset = $limit * $page;
$content .= theme('item_list', array('items' => array_slice($items, $offset, $limit)));
$content .= theme('pager',array('quantity' => count($items)));

Try above example to use simple custom pagination for theme item_list function

1 comment:

Anonymous said...

What a material of un-ambiguity and preserveness of valuable experience about unpredicted emotions.