Drupal 6 Override views pager theme function

By shane
Wed, 2012-05-09 16:12
4 comments

It is possible to override a specific pager for a specific views using a theme function in your template.php file. Here are the steps needed:

Theme Views Pager Step 1

No matter how you want your pager to look, make sure to select mini pager within views. This will allow you to take advantage of the views pager theme hook patterns. I was unable to get this to easily work when using the full pager.

Depending on how you want your pager to look, you can start with either the code that produces the views mini pager or views full pager using the options below.

Views Mini-Pager

  • In the views module, go into the theme.inc file. This is generally located at /sites/all/modules/views/theme/theme.inc.
  • Copy the theme_views_mini_pager function into the template.php file of your theme.
  • Rename the theme_views_mini_pager function to MYTHEME_views_mini_pager.

Views Full Pager

  • In Drupal 6 core code, open the /includes/pager.inc file.
  • Copy the theme_pager function into the template.php file of your theme.
  • Rename the theme_pager function to MYTHEME_views_mini_pager.

Theme Views Pager Step 2

The next step is to determine which pager theme function you want to override in your template.php file. This can easily be determined by using the following code snippet:

print('<pre>'.print_r($pager_theme,1).'</pre>');die();

This line needs to be dropped in the theme.inc file inside the views module. This is most likely located at /sites/all/modules/views/theme/theme.inc. It needs to be added in the template_preprocess_views_view function, after the pager gets set up in the code. I ended up putting this code at line 99, but can go anywhere after you see this line of code:

$pager_theme = views_theme_functions($pager_type, $view, $view->display_handler->display);

Now if you refresh the page when viewing the page that displays your view, you will get a white screen with a list of theme function names that you can use to override your views pager inside your template.php file. Use the function that is a specific as you need it to be for you particular view and use case, and replace the theme_views_mini_pager or theme_pager function with the correct function name. This will end up looking something like (replacing MYTHEME with the name of your theme and MYVIEW with the name of your view:

function MYTHEME_views_mini_pager__MYVIEW($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  //the rest of the pager code goes here
}

Theme Views Pager Step 3

This step is entirely up to you. Customize the Drupal views pager to your hearts content.

Hopefully this helps you next time you need to override a specific pager on a view. If you have any other views theme tricks, drop them in the comments.

Special Note
If you are intending to override the views_mini_pager theme function, you should probably make sure your view name does not contain a capital letter. See http://drupal.org/node/1569886 for more information.

5 Secrets to Becoming a Drupal 7 Ninja

Comments

Thanks - this is exactly what I needed. Works great with D7 too, but $pager_theme isn't inside the function anymore. I just used the Theming information link in the View to figure out the View name.

Thanks for the sharing I know this is kind a off topic however , I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa? My site goes over a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you might be interested feel free to shoot me an email. I look forward to hearing from you! Superb blog by the way!

Post new comment