Displaying a block based on the taxonomy term in the URL

I wanted to display node content in a block based on it’s taxonomy term’s URL, so that from example.com/exterior the user can see a list of nodes of term exterior. The problem is that blocks don’t pull arguments from the URL same way as a page view. This can be done by adding a term:ID argument, providing a default argument as php code. The following snippet takes the term id so that Drupal can use it as an argument for the content to be displayed:

//break path into an array
$path = explode(‘/’, $path);
$termname = array_pop($path);
//convert the dashes to spaces
$termname = str_replace(“-“, ” “, $termname);
$terms = taxonomy_get_term_by_name($termname );
$term = reset($terms);
return $term->tid;

More on this: http://drupal.org/node/781748#comment-2900002


Posted on May 22, 2011, in Uncategorized. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: