2

I want to add to alter the output of theme_pager(), and add a <li> tag, as the following:

<li class="pager_go_input last">to <input type="text" id="pager_go_input_1" class="form_text pager_form_go_input" alt="1" value="1">
  page
</li>

How is possible to do this?

Update of the question:

I want to change the Drupal pager to this style: http://www.dedecms.com/knowledge/servers/windows/list_66_1.html. Is there a module? Or: How to alter the theme_pager to get that? the pager is located at the bottom of the pager. as this displays(首页 1 2 3 4 下一页 末页 the selected downlist 共 4页33条). Compare this to the Drupal default pager. It adds a selected downlist, when selects a page from the downlist, the site then auto redirect to the specific page. The whole count pager (how many the pager have pages?) and the count of all the records in the pager.

2

You need to look at the code above and understand what it is doing. Where does li.pager-last come from? Notice that the last line uses theme('item_list') to build the result and it passes in $items. Just above that you'll see the code which adds an item to the $items array with 'class' => 'pager-last':

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

If you want to add another item after li.pager-last, you might try duplicating these 5 lines and modifying them to do what you want.

2
  • i used a simple ways to get that add the li label after the $li_last = theme() directly. if i want to use your resolution, eg:the varibale is $li_last_last. how to write the $li_last = theme()code ? – enjoylife Mar 28 '11 at 5:10
  • You need to implement your own "version" of theme_pager in your theme (copy and paste it into template.php and change the name to phptemplate_pager) and then modify it to include something like $items[] = array('class' => 'your-class', 'data' => 'your extra stuff'); – thsutton Mar 28 '11 at 7:39
1

In template.php

function THEMENAME_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global $pager_page_array, $pager_total;

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  // End of generation loop preparation.

  $li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters);
  $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);
  $li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('last »')), $limit, $element, $parameters);

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

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      if ($i > 1) {
        $items[] = array(
          'class' => 'pager-ellipsis',
          'data' => '…',
        );
      }
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters),
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' => 'pager-current',
            'data' => $i,
          );
        }
        if ($i > $pager_current) {
          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
          );
        }
      }
      if ($i < $pager_max) {
        $items[] = array(
          'class' => 'pager-ellipsis',
          'data' => '…',
        );
      }
    }
    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => 'pager-next',
        'data' => $li_next,
      );
    }
    if ($li_last) {
      $items[] = array(
        'class' => 'pager-last',
        'data' => $li_last,
      );
    }
    return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}
3
  • i am sorry, you code is the default pager style.i don't know how to add the li label – enjoylife Mar 28 '11 at 2:59
  • you can change this code in your template.php as you wish – dobeerman Mar 28 '11 at 3:30
  • but i still don't know how to add a li after the li class=pager-last – enjoylife Mar 28 '11 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.