I need to make a pager which is like the default drupal pager, only without the ''<< first" and "last >>" elements. First I did this:

I copied the theme_pager() function from pager.inc to the template.php file form my custom theme (subtheme form Zen), and renamed it to mytheme_pager()

My idea was just to remove the bits of code which would generate the first/last links. Doing this in the pager.inc file worked nicely (just for testing purpose, I know this not the proper way to do this), but doing the same thing to the function in my template.php file, doesn't work.
The pager is being created with al its elements (without the firs/last elements), the previous/next element are empty though (the elements are present in the html, but the anchors are empty). The only elements which are visible are the numbers from all pages.

So my modification works when applied to the pager.inc file, but when copying that exact function (+ renaming) to my template.php file it behaves differently. What am I doing wrong?

Here is my modified version of the theme_pager() function (note the comments without indent):

<?php
function mytheme_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.

// I removed the $li_first and $li_last
 
$li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters);
$parameters);
 
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);


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

// I removed the if statement which generated the first-link here

    
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,
      );
    }

// I removed the if statement which generated the last-link here

   
return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}
?>

Comments

Is your theme called mytheme?

Just checking - Is your theme called mytheme?
If not, the function should be the name of your theme instead of "mytheme".
e.g. If your theme is called Plato then the function should be plato_pager

You can also use phptemplate_pager as the name of that function, which is sometimes handy because then you can copy it to any themes template,php file without having to change the name.

Regards
Geoff

Regards
Geoff
The user previously known as gpdinoz

The function has the name of

The function has the name of my theme (which isn't mytheme) in it as you say. My theme is actually called 'wilvie', and the function is called wilvie_pager() . So that is not an issue.

Thanks for your reply anyway.

Syntax error

There is syntax error because the extra line $parameters);

// I removed the $li_first and $li_last
  $li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters);
$parameters);
  $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);

The other way you could do it is overide the functions theme_pager_first and theme_pager_last so they output nothing.

Regards
Geoff

Regards
Geoff
The user previously known as gpdinoz

I guess something went wrong

I guess something went wrong in copying the code to my forum post, since I got no syntax errors.

I'll try overiding the theme_pager_first, theme_pager_last functions. Thanks for the suggestion.

I'm afraid just making the

I'm afraid just making the theme_pager_first and theme_pager_last output nothing doesn't work. The pager just gets messed up.

I mainly wonder why the following happens:
After copying the complete theme_pager() from pager.inc to wilvie_pager() in my template.php file, the output is different: all elements except for the page numbers are empty (the anchor-tags are present but empty).

Why would that happen? I tried emptying the drupal cache and my browser cache.

After a bit of experimenting ....

In theme_pager change only 2 lines

  // End of generation loop preparation.

  $li_first = '';   <----------- HERE
  $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 = '';  <----------- HERE

This is because
theme('pager_last', (isset($tags[4]) ? $tags[4] : t('last »')), $limit, $element, $parameters);

returns the HTML for the "last" link

here is the full function

function phptemplate_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global $pager_page_array, $pager_total;
print_r($pager_page_array);
  // 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 = '';
  $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 = '';

  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'));
  }
}

Regards
Geoff

Regards
Geoff
The user previously known as gpdinoz

Thanks for the effort. The

Thanks for the effort. The problem I mentioned earlier isn't solved with this code though.

I've made some sreenshots to clarify: http://img222.imageshack.us/my.php?image=pagerfa0.jpg

This is your code in action, from both pager.inc and template.php (also note the corresponding html below). Why are the last/previous elements empty on the left part?

I thought you wanted ...

I thought you wanted what is shown in the image on the right.

also remove line 3 of my code

print_r($pager_page_array);

Regards
Geoff

Regards
Geoff
The user previously known as gpdinoz

You didn't misunderstood.

You didn't misunderstood. But the thing is: I don't get that output doing things on the 'proper way' (that is: not modifiying any drupal system files). The only way I can achieve this output is by modifying theme_pager() in pager.inc itself. Somehow the overriding of the theme_pager() function does not work.

Thanks again for your replies.

Finding the problem is the key

OK so we have the right code but something else is going on. It works in the garland theme for me. Try the overide code in a core theme as they have less bugs. Once you have it working in a core theme then you know the code is good and the problem is elsewhere. Then start trying different things, checking other code, spelling mistakes in function names can cause problems, is there a problem with code in your template.php file further up the page, comment out large bits of code to see what you can do without, get rid of other template files etc.

Zen is a rather complex theme with lots of other things going on so it could be a problem just with Zen. I had a look at the issues for Zen and there are some funny things happening sometimes.

Regards
Geoff

Regards
Geoff
The user previously known as gpdinoz

Gpdinoz, I added the code to

Gpdinoz,

I added the code to my template.php like you've stated here, but it seems to have absolutely no effect what so ever.
I'm using 6.6 Drupal. Could that be the reason?]
Thanks
Navs

No

It should work on all 6 versions. What theme are you using and have you cleared the cache at admin/settings/performance?

Regards
Geoff

Regards
Geoff
The user previously known as gpdinoz

I'm starting to think this

I'm starting to think this is a bug in the Zen theme. I've tried this custom theme_pager() function on different themes: the problem I mentioned occurs only in the base zen theme and zen-subthemes.

nobody click here