Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Drupal 7. I'm trying to display a block using the "Pages on which this PHP code returns TRUE" feature. The field is a single value list (text) named field_display_block so all I want to do is determine if field_display_block is set to "1".

I'm sure there are a couple of ways to do this. Any help on this would be greatly appreciated.

Thanks

Les Z

share|improve this question

1 Answer

With the following script you can check the value and return true. I've added my comments before each line.

// First check if the current page is a node
if ($node = menu_get_object()) {
 // Then, check if it is your content type
 if ($node->type == 'your_content_type') {
   // Get the value of your field
   $display_block = field_get_items('node', $node, 'field_display_block');
   // If the field's value is equal to 1, then return true
   if ($display_block[0]['value'] == '1') {
     return TRUE;
   }
  }
}
share|improve this answer
Worked great. Thanks for your help. – user20672 Sep 4 at 9:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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