Closed (fixed)
Project:
Earthish
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
25 Aug 2011 at 17:48 UTC
Updated:
28 Nov 2011 at 05:10 UTC
I was curious if it's possible and/or relatively simple to adjust the following piece of code on the page.tpl.php template to pull an image from a field on the current node as the background image, else fall back on the home-bg.jpg and the content-bg.jpg.
<?php if($is_front): ?>
<img id="main-image" src="<?php print $base_path . $directory; ?>/images/home-bg.jpg" alt="<?php print $site_name; ?>" />
<?php else: ?>
<img id="content-image" src="<?php print $base_path . $directory; ?>/images/content-bg.jpg" alt="<?php print $site_name; ?>" />
<?php endif; ?>
What I would like to do, if it is possible, is create a field called field_bgimage assign it to all content types. Then have the page.tpl.php file check the current node to see if the field_bgimage is populated and if so, display that image as the page background instead of the two fallback images currently reflected in the code above. Does anyone know if this is even possible?
Comments
Comment #1
ishmael-sanchez commentedComment #2
ishmael-sanchez commented>possible and/or relatively simple to adjust the following piece of code on the...
Depends what you consider relatively simple. Anyway, you will need to create the image field, add an image style (unless you want to size the images yourself manually), refine the page preprocess function in template.php to output a custom variable, then output that variable in the page.tpl.php.
>current node to see if the field_bgimage is populated and if so...
In my example I set fallback if there isn't anything uploaded and my field name is field_image.
Also, I changed the title in hopes that more people find this post as it's something I think some advanced themers will want to do.