Greets, first of all thanks, views is probably the main reason I am using drupal.

I am wanting to use different theme for the pager that gets outputted in a node tpl on a view like this

$view = views_get_view('new_art_gallery_view') or die ('no such view');
$view->set_display('Page');
$view->display_handler->set_option('items_per_page', 2);
$view->display_handler->set_option('use_pager', 'custom');
print $view->preview(NULL, array('a', 'possible', 'array', 'of', 'arguments'));

After checking out that in views theme.inc the function theme_views_mini_pager around line 600 is mostly a modified version of http://api.drupal.org/api/function/theme_pager/6 please excuse my very very quick and dirty hack on function template_preprocess_views_view around line 80 and made my own function theme_views_custom_pager.

  if ($view->pager['use_pager'] == 'custom'){
    $pager_type = ($view->pager['use_pager'] === 'custom' ? 'views_custom_pager' : 'pager');
    $pager_theme = views_theme_functions($pager_type, $view, $view->display_handler->display);
    $vars['pager']    = theme($pager_theme, $exposed_input, $view->pager['items_per_page'], $view->pager['element']);
  } elseif ($view->pager['use_pager'] == 'mini') {
    $pager_type = ($view->pager['use_pager'] === 'mini' ? 'views_mini_pager' : 'pager');
    $pager_theme = views_theme_functions($pager_type, $view, $view->display_handler->display);
    $vars['pager']    = theme($pager_theme, $exposed_input, $view->pager['items_per_page'], $view->pager['element']);
  }

I would really like being able to theme pagers in a more themer friendly way specific to each view, I am no programmer so I would have no idea how to do more. What a themer needs is a short example of how to create custom pager type(s) in a drupal friendly way. Also having that pager type show up in the views ui would be a big help.

Thank you for your time, I am interested in any thoughts on this issue, after searching there doesn't seem to be much more info around.

Comments

imp7’s picture

It does work you just also have to add in the views.module file an entry for every pager function you want, copy from line 32 $hooks['views_mini_pager']

  $hooks['views_custom1_pager'] = $base + array(
    'arguments' => array('tags' => array(), 'limit' => 10, 'element' => 0, 'parameters' => array()),
    'pattern' => 'views_custom1_pager__',
  );
dawehner’s picture

You can do this also in your own hook_theme

imp7’s picture

imp7’s picture

Thanks for the advice dereine, could you be a little more specific, or do you know of a link to read from that describes what you mean by that? I wouldnt know where to start :)

Gabriel R.’s picture

Title: Custom Pager markup » Theme pager in Views

I changed the title of the page to make it clearer and easier to google.

YK85’s picture

I'm having a hard to understanding how to theme the pager.
I would like to achieve something like the pager shown at http://drupal.org/project/issues/user
Is there a tutorial or can someone help? Thanks!

imp7’s picture

yaz085 is there something in particular you don't understand about the posts above? You may have to start reading the begging of the drupal handbook as I would not know where to begin to explain such a thing http://drupal.org/theme-guide/6.

I am still interested in how other developers have approached themeing the pagers individually, I haven't really changed the way I do it since I made the post.

kelvincool’s picture

Themeing a pager for a specific view is possible. For example, if you had a mini pager on a view block called ticker, the themeing functions available are:

views_mini_pager__ticker__block_1, views_mini_pager__block_1, views_mini_pager__, views_mini_pager__ticker__block, views_mini_pager__block, views_mini_pager__ticker, views_mini_pager

Then all you need to do is copy the theme_views_mini_pager function into your template.php and change it however you want. For example to only theme the pager on block 1 in my ticker view I would use theme_views_mini_pager__ticker__block_1

If you need to find out all the templates available, put this code on line 85 in theme.inc within the views/theme/ folder

var_dump($pager_theme);exit;

This will give you an output of all the themeing functions the view pager can use.

imp7’s picture

thanks kelvincool, that is pretty handy to know.

esmerel’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

OxH2’s picture

thanks for the clear info - this really helped me out

my new function did not work at first and produced next and previous links without closing tags

narrowed this issue down to the document encoding of template.php as described in this post:

http://drupal.org/node/503062

open social’s picture

nice, this is what I was searching for!

devkinetic’s picture

As an update in the latest views (d6) the line for the var_dump (as detailed in #8) is 97.

delion’s picture

Issue tags: +override pager

i have dumped the view block id's and tried multiple ones and still none of them seem to override the mini pages of this block that i have. here is the function i am using.

function Subtle_Hightlights_views_mini_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;
  // max is the maximum page number
  $pager_max = $quantity;
  // End of marker calculations.


  $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('')), $limit, $element, 1, $parameters);
  if (empty($li_previous)) {
    $li_previous = "";
  }

  $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('')), $limit, $element, 1, $parameters);
  if (empty($li_next)) {
    $li_next = "";
  }

  if ($pager_total[$element] > 1) {
    $items[] = array(
      'class' => 'pager-previous-mini',
      'data' => $li_previous,
    );
 if ($pager_current == 9){
 	$li_next = "";
 }
    $items[] = array(
      'class' => 'pager-current-mini',
      'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
    );

    $items[] = array(
      'class' => 'pager-next-mini',
      'data' => $li_next,
    );
    return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}
phponwebsites’s picture

I have created a page with 2 pager. I have displayed both pager items in tab1 and tab2. The tab2 have been displayed by default. If I click pager of tab1, then it have displayed by default tab2.

So i want to change active class based on tab's pager. For that i want to pass custom argument with page number into url. If i will do this, then i can displayed correct tab.

ie, my url should be ?page=1&type=tab1, if i click pager of tab1.

i have tried hook_views_pre_build(), but i didn't know how to pass arguments into views pager.

If i had used theme(pager), then i can pass values as argument.

Below is the sample code:

$args = array('parameters' => array('type' => 'recent'));
theme('pager', $args);

Due to above code, my url looks like 'http://www.example.com/sample?type=recent&page=1'

I want to do same for views pager.