1

I created a Drupal menu and place the resultant block in the left sidebar. On the block configuration page I went to “Show block on specific pages” > “Show if the following PHP code returns TRUE (PHP-mode, experts only).” and added the following code:

$tid = 0;
$desired_tid = 12;  // Change to the tid you want
$node = menu_get_object();
if ( !empty($node) && !empty($node->taxonomy) ) {
  foreach ( $node->taxonomy as $term ) {
    if ( $term->tid == $desired_tid ) {
       $tid = $term->tid;
       break;
    }
  }
}
return $tid;

The menu still showed up on all pages and not just the page that had the taxonomic term that had ID=12.

I then tried using the code:

$desired_tid = 12;  // Change to the tid you want
$node = menu_get_object();
if ( !empty($node) && !empty($node->taxonomy) ) {
  foreach ( $node->taxonomy as $term ) {
    if ( $term->tid == $desired_tid ) {
      return TRUE;
    }
  }
}

Same effect, the menu still was on all pages. I have disabled caching, flushed the cache, and rebooted the server, all to no affect. Any idea what I might be doing wrong?

1
  • Been there, done that! – Ashlar Nov 9 '11 at 0:17
1

If you will put more blocks based on taxonomies or maybe for certain content type i would recommend the context module:

http://drupal.org/project/context

With context you can set conditions with a friendly UI for display blocks in your drupal instalation.

0

The most likely cause is you forgot to put your code inside <?php ?>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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