0
$node=node_load(18);
$logo_img = file_create_url($node->field_site_logo[$node->language][0]['uri']); //origional image path
$show_logo = $node->field_options_site_logo['value']; //original image path
if(isset($logo_img)) {
  $web_logo = theme('image_style', array('path' => $node->field_site_logo[$node->language][0]['uri'], 'style_name' => 'site_logo'));
  print $web_logo;
}

I created CMS option of uploading site logo. I also added an option of show/hide this logo (form in node 18). Using the above code, I am able to load the image but don't know how to hide it if this option is not selected. I just want to know how to get the value of this check box. I can write the condition to show or hide this. Please help. Also, please let me know how to include alt option to the above image.

enter image description here

enter image description here

0

Where do you put this PHP code? If it's in the page.tpl.php, then you can use the $logovariable to display the field or not.

Otherwise, this configuration is available in your theme. So you need to get your theme configuration, with theme_get_setting. You should have a variable 'toggle_logo' or something like this. The full code would be

$test = theme_get_setting("toggle_logo");
if($test) {
   //Put your code here
}

If you're using different theme, or you need to get this value for a specific theme, then you need to pass your theme name as second parameter of the function, for example:

$test = theme_get_setting("toggle_logo", "my_custom_theme");

[EDIT FULL ANSWER]

So you just need to check the value of the field field_options_site_logo before outputing the image:

$node=node_load(18);
if(isset($node->field_options_site_logo['und'][0]['value']) && $node->field_options_site_logo['und'][0]['value'] == 'yes') {
  $logo_img = file_create_url($node->field_site_logo[$node->language][0]['uri']); //origional image path
  $show_logo = $node->field_options_site_logo['value']; //original image path
  if(isset($logo_img)) {
    $web_logo = theme('image_style', array('path' => $node->field_site_logo[$node->language][0]['uri'], 'style_name' => 'site_logo'));
    print $web_logo;
  }
}
  • thanks Matt. Actually, my friend have trouble in changing logo image. So, I gave him an option of uploading it & option of hiding it in back-end. For this I created a content type (see image) There he can upload a image in and if he un-check the option to show logo in website, This logo images won't be visible in front-end. Now, I am able to print the logo using the above code but don't know how to check if the check-box is selected or deselected. – Suresh Alagar Jan 2 '14 at 16:16
  • Suresh, you need to get the value of the custom field you created, something like $node->field_other_options_show_logo["value"] or something like this. If you're using the devel module, just use dsm($node) to see what is the path to access the field value. – Matt Jan 2 '14 at 16:19
  • I've uploaded the screenshot, which I got as output using dsm($node) – Suresh Alagar Jan 3 '14 at 4:38

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.