You are here: Home » Blogs » derek's blog » Views for group navigation

Views for group navigation

Creating cool navigation utilities is a snap with Views. This post will focus on my efforts to put together a view that outputs a list of groups that are in the same category as the group we are currently looking at.

I believe this would be possible with contexts in panels however I am looking to build just a single block that I can do with as I please.

Step 1: To get started I navigate to the views administration screen at /admin/build/views and create a new view named group_navigation.

Step 2: After my view is created I can edit it at /admin/build/views/edit/group_navigation.

Step 3: Set up the displays by adding a block display (the only one I need).

Step 4: I set the items to display to 0 for an unlimited number. I do not expect that we will have hundreds of groups in any one category. I would prefer not to use a pager for navigation.

Step 5: Next add the argument. In this case the argument is Taxonomy: term id with depth.

Step 6: Configure the argument handling code. For me the code looks like this:

if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
  return arg(2);
}
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $n = node_load(arg(1));
  foreach ($n->taxonomy as $t) {
    if ($t->tid) { return $t->tid; }
  }
}

Step 6.1: Optionally you may set the title be set by the argument passed in. To do this, simply add %1 in the "Title" field within the argument configuration.

Step 7: Set the sort criteria to whatever you like. You can even leave it if you just don't care to sort.

Step 8: Set the view to filter on node type. You will want to filter on your site's group type. For me this is "organization."

Step 9: Save your changes and enable the block in the region of your choosing.

Views can be used to build some pretty neat dynamic content displays as well as navigation tools. Views can be a bit tricky to work with though so we encourage you to play around with views as much as possible.

Add a comment

Post new comment

You must have JavaScript enabled to use this form. If you are seeing this message, you need to turn JavaScript on and refresh the page. If you are unable to enable JavaScript, you may direct inquiries to questions[at]collectivecolors[dot]com
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Hide comments