Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal 6 Override views pager theme function

Parent Feed: 

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.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web