Previous/ next navigation in taxonomy terms Due to some complex project, I would like to organize navigation between taxonomy terms programmatically, with generation of custom links.

Example of navigation I need in vocabulary "fruits" with following terms, situated in same order in taxonomy management admin module :


apple -> has next link to apricot
apricot -> has previous link to apple, has next link to banana
banana ->  has previous link to apricot, has next link to cherry
cherry ->  has previous link to banana


The question, is : what is the most convenient method to get the id of previous and next term, in the same order as they organized in vocabulary ?

It's seems what in current taxonomy API of Drupal 7 there is no specific functions to do it in simple way.
We will make a view, load the term from contextual argument, get its weight into $static variable, and check on each row if row's term's weight is higher than our arg's one.


Create a view of terms, order them by weight.
Display only 1 item.
Add and hide taxonomy term: weight field.
Add a contextual filter : Taxonomy term: Term ID
Add a PhP filter and :


Setup code :

$static = taxonomy_term_load($view-&gt;args[0]);
$static = intval($static-&gt;weight);


Filter code :

if(intval($data-&gt;taxonomy_term_data_weight) &lt; $static) {return TRUE;}


If you're sure that your terms have following weight, you can use that filter code : 

if(intval($data-&gt;taxonomy_term_data_weight) == intval($static - 1) || intval($data-&gt;taxonomy_term_data_weight) == intval($static + 1) ) {return TRUE;}


to get the next and following terms. But careful with 0 and last values... :)

And of course, in that case, you have to display all items in the view.