function theme_pager

7 pager.inc theme_pager($variables)
4.6 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $attributes = array())
4.7 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array())
5 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array())
6 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9)
8 pager.inc theme_pager($variables)

Returns HTML for a query pager.

Menu callbacks that display paged query results should call theme('pager') to retrieve a pager control so that users can view other results. Format a list of nearby pages with additional query results.

Parameters

$variables: An associative array containing:

  • tags: An array of labels for the controls in the pager.
  • element: An optional integer to distinguish between multiple pagers on one page.
  • parameters: An associative array of query string parameters to append to the pager links.
  • quantity: The number of pages in the list.

Related topics

12 theme calls to theme_pager()
hook_search_page in modules/search/search.api.php
Override the rendering of search results.
node_admin_nodes in modules/node/node.admin.inc
Form builder: Builds the node administration overview.
poll_page in modules/poll/poll.pages.inc
Menu callback to provide a simple list of all polls available.
profile_browse in modules/profile/profile.pages.inc
Menu callback; display a list of user information.
search_extra_type_search_page in modules/search/tests/search_extra_type.module
Implements hook_search_page().

... See full list

File

includes/pager.inc, line 320
Functions to aid in presenting database results as a set of pages.

Code

Non-displayable characters.

Comments

When calling theme('pager') outside a pager query, it's necessary to initialize the pager first with a call to pager_default_initialize()

Thank you, this helped me. Achieved pager this way

pager_default_initialize($total, 1, $element = 0);
$output = theme('pager', array('quantity' => $total));

Is there someone who can tell me how to set the pager limit?
In Drupal 6 there is a simple way like this:

theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9)

But in Drupal 7 it look like this:

theme_pager($variables)

Thanks for your help.

The answer is on #1, but for more explicit example see http://api.drupal.org/api/drupal/includes!pager.inc/function/pager_defau...

More likely, you will probably need to do something like

<?php
$query
= db_select('some_table')->extend('PagerDefault');
?>

(which you will find at pager_default_initialize).

I'm also trying to change the pager limit in Drupal 7. Specifically I want to take the content area on my webpage and display all content nodes ... not just the default 10 nodes that seems to be the limit.

.... But I don't understand the previous comments and the references to pager_default_initialize. Disclaimer: I have only a shallow understanding of Drupal 7 - so I'm largely operating on educated guess work to get things working.

I have a custom theme called: mytheme and here's what I have done so far. Note that after each attempt, I have used the Drupal 7 administrative interface on my website to clear all caches. I've also reloaded the pages after clearing my browser cache.

  • I have tried to modify my template.php file by adding the pager_default_initialize function call to my mytheme_preprocess_page(&$vars) function as follows:
    function mytheme_preprocess_page(&$vars)
    {
        ..... 
        pager_default_initialize($total, $limit=30, $element = 0);
    }

    This doesn't work.

  • I have tried to modify the same function in template.php as follows:
    function mytheme_preprocess_page(&$vars)

        // Select nid from published nodes with 20 pager limit
        $query = db_select('node', 'n')
            ->condition('status', 1)
            ->extend('PagerDefault')
            ->limit(30)
            ->fields('n', array('nid'));

        $results = $query->execute();
       
        pager_default_initialize($total, $limit, $element = 0);
    }

    This doesn't work either. I've tried running the code without the call to pager_default_initialize too.

  • I've also tried adding a separate function to my template.php file as follows - clearly this is Drupal 6 format function, but thought I'd try anyway:
    function mytheme_pager($tags = array(), $limit = 30, $element = 0, $parameters = array(), $quantity = 9)
    {
        if (drupal_is_front_page())
        {
            return "";
        }
        else
        {
            return theme_pager($tags, $limit, $element, $parameters, $quantity);
        }
    }

    This doesn't work. It does remove the pager link buttons but nothing more.

  • Finally, I've tried the same function in Drupal 7 format: mytheme_pager($variables) with all combination of the above three code examples inside the function.

Absolutely any help pointing out the right direction to take would be helpful... in fact, if anyone can suggest a way to do this through the Drupal 7 Web Administration interface - that would be amazing! Thanks!

Aaron, did you ever get a response to this. I'm trying to do the same but I'm not following on what is need to change the pager limit.

You can try this, it works for me in D7:

function [THEMENAME]_pager($variables) {
  if ($variables['quantity'] > 5) {
    $variables['quantity'] = 5;
  }
  return theme_pager($variables);
}

For what it's worth -- from within theme_pager ($variables), changing the value of $quantity does the trick.

"theme_pager" does not have any call to "theme_pager_link", instead it has calls to "theme_pager_previous", "theme_pager_next" etc., which in turn call "theme_pager_link". Now, "theme_pager_link" accepts the "attributes" in the "variables" but the others do not. Does this mean, if I want to add an attribute (like changing the default titles), I have to override "theme_pager_previous" etc. ? Should not I be able to do that just by overriding "theme_pager"?

"theme_pager" does not have any call to "theme_pager_link", instead it has calls to "theme_pager_previous", "theme_pager_next" etc., which in turn call "theme_pager_link". Now, "theme_pager_link" accepts the "attributes" in the "variables" but the others do not. Does this mean, if I want to add an attribute (like changing the default titles), I have to override "theme_pager_previous" etc. ? Should not I be able to do that just by overriding "theme_pager"?

Sorry for double post, there is a bug in this page too - the comment preview shows the error that "Function, file, or topic" is required and shows a validation error with the search form.

pager_default_initialize(888,10);
$args = array('quantity' => 12,'tags' => array('<<','<','','>','>>'));
theme('pager',$args);

Hope this can help.

I'm using this in some custom code in my theme:

$query = db_select('node', 'n')->extend('PagerDefault')->limit(3);

And I was also making use of an extra parameter (?c=27) in my URL string, I found I had to do this to make pagination work:

$args = array('element' => 1, 'parameters' => array('c' => 27));
theme('pager', $args);

Hope that helps someone.