0

I am trying to create "previous/next node" navigation on my nodes in order to show 2 previous and 2 following nodes in the term currently being viewed. Here is the code that displays 2 prev and 2 next nodes, but it is not taxonomy aware, i. e. it sorts nodes according to their IDs:

Prev/Next node navigation with a thumbnail in a full node

If I add a node in the term after some time, it will display this node as the last one, not as a "neighbour" of a node uploaded e.g. 3 months ago.

I have tried with "n.title", but it doesn't change anything. Ideally, it should order them either by titles or url aliases.

Thank you in advance!

Community
  • 1
  • 1
take2
  • 616
  • 2
  • 17
  • 31

2 Answers2

0

it's not querying the taxonomy tables in the database query. You probably want to add a variable to the function as such dad_prev_next($current_node = NULL, $op = 'p', $tid) to pass it the term ID and then add that to your query through an inner join

SELECT n.nid, n.title
FROM {node} n
INNER JOIN {taxonomy_index} t
ON n.nid = t.nid
WHERE n.nid $sql_op :nid
AND t.tid = :tid
AND type IN ('photos')
AND status = 1
ORDER BY n.nid $order
LIMIT 1

I think that should be pretty close, then just pass that at the end of db_query db_query($sql, array(':nid' => $current_node -> nid, ':tid' => $tid));

Antonio Torres
  • 446
  • 3
  • 9
  • Thank you for your answer, but I am a coding beginner and don't know where exactly should I put this code. I tried to combined it with the quoted code, but there are always some errors. – take2 Jun 20 '12 at 19:17
0

Newer version of Previous/Next module has multiple options for sorting prev/next nodes. You can use the workaround to get thumbnails too:

http://drupal.org/project/prev_next http://drupal.org/node/1790290

take2
  • 616
  • 2
  • 17
  • 31