June 04, 2014

June 04, 2014
In this article, we are going to discuss about How to use the WordPress like pager in Drupal website. Most of the people preferred the Wordpress kind of pagination in drupal based site. But by default, Drupal provides the number pagination < 1 2 3..> . so here is the snippet to get the Wordpress kind of pagination which overrides the default pagination of drupal.

<?php
function yourtheme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global $pager_total;

  $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
  $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);

  if ($pager_total[$element] > 1) {

    if ($li_previous) {
      $items[] = array(
        'class' => 'pager-previous', 
        'data' => $li_previous,
      );
    }

    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => 'pager-next', 
        'data' => $li_next,
      );
    }
    return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }

?>

Add the above code snippet in your theme's template.php file and clear the cache and then check it. It will work.

The above code will solve someone's headache.

0 comments:

Post a Comment