I have a news page with two views: one displaying the latest news item (a full node view) and a block in the sidebar containing the latest news items, with an Ajax pager.

This works great, but I have one issue: when I open an older news item, by clicking a link on page X from my block, the pager jumps back to page 1.

Is there a way to add the current pager number to all links in my block?

So that my links are like: http://www.site.com/news/title-of-news?page=2

Comments

jibort’s picture

I have the same problem. Do you solved that? thanks.

dawehner’s picture

Status: Active » Fixed

This is not possible at the moment.

Here is a example handler which does this.

<?php
// $Id: $

class ef7_views_handler_field_custom extends views_handler_field_custom {
  function render_as_link($alter, $text, $tokens) {
    $value = '';

    if (!empty($alter['prefix'])) {
      $value .= filter_xss_admin(strtr($alter['prefix'], $tokens));
    }

    $options = array(
      'html' => 'true',
    );

    // $path will be run through check_url() by l() so we do not need to
    // sanitize it ourselves.
    $path = $alter['path'];

    // html_entity_decode removes <front>, so check whether its different to front.
    if ($path != '<front>') {
      // Use strip tags as there should never be HTML in the path.
      // However, we need to preserve special characters like " that
      // were removed by check_plain().
      $path = strip_tags(html_entity_decode(strtr($path, $tokens)));
    }

    // If the path is empty do not build a link around the given text and return
    // it as is.
    if (empty($path)) {
      return $text;
    }

    // Parse the URL and move any query and fragment parameters out of the path.
    $url = parse_url($path);
    if (isset($url['query'])) {
      $path = strtr($path, array('?' . $url['query'] => ''));
      $options['query'] = $url['query'];
    }
    if (isset($url['fragment'])) {
      $path = strtr($path, array('#' . $url['fragment'] => ''));
      $options['fragment'] = $url['fragment'];
    }

    $alt = strtr($alter['alt'], $tokens);
    // Set the title attribute of the link only if it improves accessibility
    if ($alt && $alt != $text) {
      $options['attributes']['title'] = $alt;
    }

    $class = strtr($alter['link_class'], $tokens);
    if ($class) {
      $options['attributes']['class'] = $class;
    }

    $target = check_plain(trim(strtr($alter['target'],$tokens)));
    if (!empty($target)) {
      $options['attributes']['target'] = $target;
    }

    // If the query and fragment were programatically assigned overwrite any
    // parsed values.
    if (isset($alter['query'])) {
      $options['query'] = strtr($alter['query'], $tokens);
    }
    if (isset($alter['alias'])) {
      // Alias is a boolean field, so no token.
      $options['alias'] = $alter['alias'];
    }
    if (isset($alter['fragment'])) {
      $options['fragment'] = strtr($alter['fragment'], $tokens);
    }
    if (isset($this->options['alter']['language'])) {
      $options['language'] = $this->options['alter']['language'];
    }
    // Here comes the customisations:
    // Add the ?page parameter to the site..
    $page = isset($_GET['page']) ? $_GET['page'] : '';
    if ($page) {
      $options['query'] = $options['query'] ? $options['query'] .'&page='. $page : 'page='. $page;
    }

    $value .= l($text, $path, $options);

    if (!empty($alter['suffix'])) {
      $value .= filter_xss_admin(strtr($alter['suffix'], $tokens));
    }

    return $value;
  }
}

but this is really hacky.

Status: Fixed » Closed (fixed)

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

FreddieK’s picture

subscribe.

Anonymous’s picture

Hello

I have the same problem. When I click on a link from the second page of the pager, the content opens, but the pager jumps back to page 1.

So here's what I have. I have a news content type where I show a views block. I use the Viewfield module to show the views block on the news content page. The views block shows a title ( links to node ) and date, Style - Unformatted, StyleRow style - Fields, Use AJAX - Yes, Use pager - Mini, Items to display - 5. So far so good.

Now lets say I have 15 news pages, this will give me three pagination pages in the views block. If I go to page 2 of the pagination and click on News 8, News 8 will open, but the pagination in the views block will jump back to page 1. What we would like to have is that the pagination stays on page 2.
If you check the html source of News 8 you'll see that there's a class="active" on the link item of News 8, which is good since we need some kind of reference in the views block. We need some kind of checkbox in the User pager setting that says "Show pagination page with active item", so when opening News 8 the paginator in views block will automatically jump to page 2.

This sounds easy but I guess it's not since we don't have this option yet. What we have in this example are 15 items, and views show only 5 at once, so views takes the first 5 items and shows them. What we need is that views checks all 15 items, searches for the active item and then according to this shows the pagination page. In smaller and simple cases this is would be o.k. but when you have 400 items to check for an active item, I guess this would slow things down on the website.

The views scrollable module kinda works this way, it shows all items and knows where the active item is so it scrolls down to the active item. This is what we need except we don't need things to be scrollable, we need this with pagination.

I think we would need the class="active" on the parent div element of the active item. In this case it would be

. Since we can have custom outputs for a field, the active class to search for would need to be somewhere more reasonable than a link.

Is it possible to add such an option to views or are there some limitations which makes this impossible to accomplish ?