Default functionality of pager is that pager shows list of items on multiple pages and you can possibly open one of the item (node or something else) by clicking on it (you will be redirected to a page of that item or node).

Problem definition:

But what if there is a pager showing list of items (nodes) in left side of page and also opened item (node) from that pager in right side of page?

Problem is that the pager is present at the same page as opened item, therefore we have to force pager to show that position (page of pager) where the opened item is. Pager should not show first "page of pager" because that item can possibly be at another "page of pager".

My solution

I've found my own workaround in order to define what "page of pager" should be displayed by adding a 'findpage' parameter to the links of pager items. If this parameter is present in url, my code will calculate the "page of pager" on which this item is and redirect again to url with proper 'page' parameter that defines what page of pager has to be shown. My code is:

// find page of selected project if 'findpage' is present
if (isset($_GET['findpage'])) {

    $item_order = null;
    foreach($items as $key => $item) {
        if (intval($item)==arg(1)) { $item_order = $key; }
    $page_no = floor($item_order/PAGER_PROJECT_COUNT);

  // redirect to the same url, but with page argument
  drupal_goto(arg(0).'/'.arg(1), array('query'=>array('page' => $page_no)));

// if there is no 'findpage' load project info and return template with pager...

There are links like project/5?findpage, project/12?findpage ..., where the number is id of the project. Callback of this links defined in hook_menu() is loading the project right after the code above (when the position of project in pager is known) and returning template (with pager and project info). So the process has two steps:

  • Call the callback when the link with 'findpage' parameter is clicked and find the position in pager
  • redirect from that callback to the same page, but without 'findpage' parameter and with 'page' parameter (project/12?page=2)


Is there any suitable Drupal solution for this?

  • I don't completely understand your setup. Are you using Views to display this? When you say that the project info is on the same page, do you load it via JS (e.g. push state), it just scrolls to particular part of the page (e.g. named anchors) or it's a new page, but the block with pager is still displayed? – Aram Boyajyan Feb 22 '16 at 13:23
  • I am using my own template to display project info and loading the project right after that code shown in the question. And no, Im not using JS to load project info. It is the new page (project/12, project/25...) where the number in url is id of the project, but there is "the same" pager in my template. I'll edit my question. – Incredible Feb 22 '16 at 13:54

Your Answer

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

Browse other questions tagged or ask your own question.