Hello,

I am trying to add next/back buttons for a set of nodes on my site. To do this I created a view that displayed one node per page, as detailed here: http://drupal.org/node/58410. However, this handbook entry is missing one important detail: how can I now link to a particular node in this view? Somehow I would need to determine which page it is on. Anyone know how this can be done?

Thanks,
kevin

Comments

koshea’s picture

Hm...an update, I'm getting close. I created this function:

function views_find_node($view, $nid) {
  $res = views_build_view('items', $view);
  foreach ($res['items'] as $page => $item) {
    if ($item->nid == $nid)
      return $page;
  }

  return NULL;
}

and it is working and returning the correct page. Now my only problem is that once this function has been called the pager will not display on the actual view, they must be sharing some resource...

koshea’s picture

OK, so I changed my code a bit now to use a bit of a lower level method of getting the items, not sure if this is the best solution but it works so I thought I would share it with anyone else who is interested:

function views_find_node($view, $nid) {
  $info = _views_get_query($view, array(), array());
  $query = db_rewrite_sql($info['query'], 'node');
  $result = db_query($query, $info['args']);
  while ($item = db_fetch_object($result)) {
    $items[] = $item;
  }
  foreach ($items as $page => $item) {
    if ($item->nid == $nid)
      return $page;
  }

  return NULL;
}