[support] PHP: block visibility by term

William Smith william.darren at gmail.com
Wed Aug 6 12:08:49 UTC 2008


Add "return $make_block_visible;" (without the quotes) as the last line
directly above the closing php tag ("?>")


On Tue, Aug 5, 2008 at 3:39 PM, crozilla <crozilla at gmail.com> wrote:

> All,
>
> I kinda know what I'm doing in Drupal, but this trick has baffled me.
> This is what I want to have happen:  When the page has the term 221,
> block/24 is visible, when the page doesn't have the term, the block is
> disabled. Sounds simple, right?
>
> Here is code I found on Drupal that seemed to do what I wanted, but
> didn't work for some reason. I don't really know PHP that well, and was
> hoping someone could point out the problem.
>
> ------------------
> |
> <?php
>  //code snippet for causing block to show based on a node's taxonomy term.
>  $make_block_visible = FALSE;
>  $term_id_to_trigger_show_block = 221;
>
>  if ((arg(0) == 'node') && is_numeric(arg(1))) {
>    $terms = taxonomy_node_get_terms(arg(1));
>    foreach($terms as $term) {
>      if ($term->tid == $term_id_to_trigger_show_block) {
>         $make_block_visible = TRUE;
>      }
>    }
>  }
> ?>
>
> ------------
>
> |Also, is this possible using a CCK text field, instead of a category
> term? That would be ideal.
>
> Thanks,
>
> Peter
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20080806/06e75340/attachment-0001.htm 


More information about the support mailing list