By alexmoreno, 20 December, 2012

Paginating the results in Drupal is incredible incredible easy. You just have to remember the two "magic functions":

 

  • pager_query($sql, $count);
  • theme('pager',10);

 

pager_query substitutes the typical db_query. Just something like that: 

 

  • // $resource = db_query($sql);  // -> old sentence without pager
  • $resource = pager_query($sql, $count); // -> pager

 

Then, we simple come back to the function that is called by our hook_menu, and we change:

  • return theme('list_products')

with

  • return theme('list_products') . theme('pager',10);

 

It couldn't be easier, could it? :-). In fact it is harder to undertand the documentation and the different howtos and tutorials which you can find than the process itself.