2

The client I'm building a site for has a collection of content that they want paged by its ReleaseYear Field. The pager they want should look like:

[ < | 2011 | 2012 | 2013 | 2014 | 2015 | > ]

How I build a pager like that?

1

As a clue, you should alter the theme_pager_link function. copy this function in the template.php, if the years are started from 2001, you need to alter the pager so that every link of the pager be summed with 2000, it is the function

function THEME_pager_link($variables) {
  $text = $variables['text'];
  $page_new = $variables['page_new'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $attributes = $variables['attributes'];

  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
    $parameters['page'] = $new_page;
  }

  $query = array();
  if (count($parameters)) {
    $query = drupal_get_query_parameters($parameters, array());
  }
  if ($query_pager = pager_get_query_parameters()) {
    $query = array_merge($query, $query_pager);
  }

  // Set each pager link title
  if (!isset($attributes['title'])) {
    static $titles = NULL;
    if (!isset($titles)) {
      $titles = array(
        t('« first') => t('Go to first page'),
        t('‹ previous') => t('Go to previous page'),
        t('next ›') => t('Go to next page'),
        t('last »') => t('Go to last page'),
      );
    }
    if (isset($titles[$text])) {
      $attributes['title'] = $titles[$text];
    }
    elseif (is_numeric($text)) {
      $text = $text + 2000;  ------>>>>> in this line every number is added with 2000
      $attributes['title'] = t('Go to page @number', array('@number' => $text));
    }
  }

  // @todo l() cannot be used here, since it adds an 'active' class based on the
  //   path only (which is always the current path for pager links). Apparently,
  //   none of the pager links is active at any time - but it should still be
  //   possible to use l() here.
  // @see http://drupal.org/node/1410574
  $attributes['href'] = url($_GET['q'], array('query' => $query));
  return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
}

the indicated line with ------>>>>> add every number with 2000, the only shortage of this solution is that the current number won't be summed with 2000. A few modification to this code will solve this problem as well. you can also add any css class to $attributes variable.

| improve this answer | |
  • Can I build something like this such that it only appears on a particular page, or am I overriding the general function? – Robert D. Mar 17 '15 at 20:00
  • general function – M a m a D Mar 17 '15 at 22:02
0

I'd do this the following way :

  • ReleaseYear would be a taxonomy.
  • Then you'd have it defined in your view an exposed filter.
  • And you'd theme your filter to be displayed as links.

Does that make sense to you ?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.