Nodequeue tricks - Per section block

I assume that if you've build a relatively large site, you've stumbled on Nodequeue by now ( summary: it allows you to create lists of arbitrarily ordered nodes ). But clients always had a thing for imagining things that are normally tricky to do, and one of them is to create a block that has arbitrarily ordered content per section of the site, usually by taxonomy term.

Let's assume you have vocabulary Objects, with terms Car, Guitar, and Beer. You have a number of stories tagged with each of those terms. You would like to have a views block, that depending on the term, selects the appropriate nodequeue and displays the nodes contained.

Normally, you should define a relationship to Nodequeue: qid , and decide whether to require it. You don't need to limit it yet. Then use Nodequeue: Position as the sorting method to maintain the nodequeue defined sorting. Finally, define any fields and/or filters as needed ( I only use a filter of Node: Published to allow for scheduling )

On to the meat of things: define a views argument of type Nodequeue: Queue Id, and choose to provide a default argument, PHP type. What we need to do now, is map the current term id to the queue id of interest, and return that number, as shown here:

$qid = false;
if ( drupal_is_front_page() ) {
    $qid = '5';
} elseif ( arg(0)=='taxonomy' && arg(1) == 'term' ) {
  $map = array ( 11=>6, 8=>7, 6=>8, 12=>9 ) ; // Map tid to qid
  $qid = $map[arg(2)];
return $qid;

In the above code, we initialize $qid to be false, so that if we are on an unknown location the block will be hidden. If we are on the front page, pick a queue. If we are on a term page, map the term id ( eg 11 ) to the required nodequeue id ( eg 6 ) and return that.

From there on, you only need to worry about theming the view output :)

Image is an actual product from found here