It would be nice if I could configure blocks to display/not to display based upon the taxonomy of the current displayed node.

Hypothetical examples of use:
* Open Source OS Web Page: I could have a block displaying a feed from a site with Linux Kernel news when viewing a node classified under the "Linux Kernel" taxonomy term (node/view/4). The block would also show when viewing all nodes classified under this taxonomy term (taxonomy/page/or/12).
* Regional News / Discussion Site: When viewing any node containing a movie review, a sidebar might display a block with links to local movie theatres. The block would also show when listing all movie reviews (the taxonomy page).

Currently, this functionality can only be accomplished by someone with the "administer blocks" permission adding the path to each node and taxonomy view page in regex form. This means that, for this to work, an administrator must update the block administration page every time a node is added for which we'd like the block displayed. This is tedious for a small site, and impossible for a large one.

How might we go about implementing a better solution?

Comments

moshe weitzman’s picture

TDobes’s picture

"taxo powered blocks" actually do something QUITE different from what I'd like to see. That page seems to discuss creating a block which would display links to all nodes within certain taxonomy terms. While useful, that's not what I'm attempting to accomplish. I'm looking for a further-enhanced ability to specify, as the site admin, when a block does or does not appear. (a supplement to the current regexp system)

I'd like to be able to assign a block to taxonomy term 1, then it would display:
- when viewing the taxonomy term 1 page (taxonomy/page/or/1) or a page with taxonomy term 1 items on it (taxonomy/page/or/1,2,3)
- when viewing a node associated with tid 1 (i.e. node/view/12)
- when the criteria specified by the regexp are satisfied

Hopefully, this clarifies what I was looking for.

herbivorous’s picture

You can write custom blocks that display via

$theme->block($subject, theme_item_list($output));

but which never execute this line if certain criteria aren't met. In which case, no block appears. I discovered this essentially by accident in trying to develop a block that would appear, but some bugs gave me no result for a while. But this might be the sort of tool you're looking for.

jasonmcmunn’s picture

I need exactly what Tom needs. I'm hoping someone has told him the info, but I can't figure out how to contact him directly. I need to know how to get the category of the current item, and based on that I can decide to display my block or not. I really need exactly what he asked origionally. Does anyone have an answer?

Thanks!

TDobes’s picture

jasonmcmunn:
Such a feature does not currently exist in Drupal. (That's why this feature request is still active.) It can be done, but it's not particularly easy.

A hack-ish solution might be to use some custom PHP code in a block. Of course, to determine the taxonomy of a currently-displayed node, you'd have to use node_load, which would add an extra db query and thus increase page generation time. Once killes' node_load caching patch lands, this will no longer be a problem.

But... none of this makes it easier for non-PHP-savvy admins to accomplish this task.

restyler’s picture

May be my code can help you.

<?php 
$tid = 2; //vocabulary term, where we want out block to display
if (arg(0) == 'node' && is_numeric(arg(1))) 
{ 
  $nid = arg(1); 
  $terms = taxonomy_node_get_terms($nid); 
  if (isset($terms[$tid])) 
  { 
    echo "We are in term #$tid, so you see this block"; 
  } 
} 
?>  
LAsan’s picture

Version: x.y.z » 7.x-dev

Still feature request?

thatnewguy’s picture

In same similar situation myself

thomasmurphy’s picture

subscribing

jroth’s picture

subscribing

docmorphe’s picture

subscribing

emdalton’s picture

I've been using this code with D5:

  $myterms = array(39, 59, 85, 114); // list the ids of the terms you want
  // This will show on all nodes having this term
  if ((arg(0) == 'node') && is_numeric(arg(1))) {
    $terms = taxonomy_node_get_terms(arg(1));
    foreach($terms as $term) {
      if (in_array($term->tid, $myterms)) return TRUE;
    }
  }
  // This will show on the index page for that term
  if ((arg(0) == 'taxonomy') && (arg(1) == 'term') && (in_array(arg(2), $myterms))) {
    return TRUE;
  }
  // Otherwise
  return FALSE;

I've just upgraded to D6 on a staging server, and now all the blocks are showing everywhere. (I've checked my terms-- they haven't changed.) I'd really like an easier way of doing this, e.g. assigning taxonomy terms to blocks with a pick-list and configuring a setting to do this automatically for all the indicated blocks.

emdalton’s picture

Thanks to eojthebrave, I now have working php code for my blocks in D6: http://drupal.org/node/507540

It would still be nice to be able to pick particular taxonomy terms for blocks and refer to them more easily in the block configuration, e.g. the way one can specify particular pages a block will display on (or not).

sun.core’s picture

Version: 7.x-dev » 8.x-dev
dialn’s picture

I also need this function in Drupal 7, not how I tested the module context, blockterm but the block does not appear anyone has gotten in D7

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

This should be possible with Rules (and directly in core with Views blocks). Anything else to be done?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Reading the comments agree with #16

Closing as outdated.

If still a valid request please reopen with an updated issue summary