I have a complex view that queries and presents a lot of news articles depending on year and month contextual filter arguments. Everything works fine so far. However, now I want to show kind of context menu next to the view result that looks like this (shows multiple screens with different menu content depending on current display):

shows multiple screens with different menu content depending on current display

What is the best/most elegant way to realize such a context menu? (no ugly hacks)

What I've already tried

I tried to accomplish that using the Views UI – no luck. Creating two different View blocks (one for a list of years and one for the months of currently selected year) didn't work, because in order to get a distinct result set I need identical fields that are used for "collapsing". The field I used was "Post date" – and this always differs.

I guess that I must write a custom module where I leverage the Views API and create that markup for the context menu. But where do I start? And how can obtain the current contextual filter arguments?

2 Answers 2


Not really an answer, but perhaps a lead. In Drupal 6, a similar thing was accomplished with the book navigation block. You could have the book navigation block filter to a certain number of steps up/down tree from the node page that you were currently viewing.

I am not sure how this could be accomplished with existing views configuration, as I think tree navigation is not a common thing for views.

This is more the kind of trick I would expect to find in Taxonomy, based on the vocab's hierarchy. There, navigation can be a more certain thing, as the structure is defined in the vocab, and they are just filling the tree leaves with tagged nodes. Again with the Drupal6 reference, but perhaps you can scavange code from http://drupal.org/project/taxonomy_treemenu

If you do code something, release it back to the community?

  • Thanks for your response! In the meantime I found solution. I created two Views blocks and implemented some views alter hooks where I inject values for contextual filter arguments. Works like a charm (even caching).
    – petabyte
    Aug 8, 2012 at 15:53

Perhaps views tree can give you what you need


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.