tags:

views:

243

answers:

4

I know this can probably be done with CCK and a view, and maybe a logo content type. But I was wondering if anybody knows of the BEST way to do the following (perhaps there is a module that does this already):

I want SEASONAL displays of my logo. I.e. If I create a CHRISTMAS version of my logo, with for example a a christmas hat in the logo, this must be shown on Christmas, or 7 days before christmas. This 7 days must be changeable on a PER LOGO basis. I.e. I might want to show christmas logo for the whole of december, but the holloween one only for one day.

It must automatically choose between the various logos and ALSO, cater for LANGUAGES. I have three languages and therefore three different logos on my site.

+1  A: 

If it was a set of very simple rules, I'd just do that from the template page (if it is december, include this logo, if not include this other logo, etc...).

If you want this to be fully customizable, then I'd make a small module, and perhaps a logo CCK translatable content type, with an image and date ranges, so it would select the images appropriately according to your rules. Then the module would export a block to be put in one of the regions, say the header. This would also be language-aware.

I think that a view may be not sufficient to do the complete thing, it needs to be a bit complicated...

Palantir
Ah. I thought as much. I'm going to create a content type, and then just put the code and logic directly on the page. Maybe extract it into a seperate file. Thanks Palantir!
RD
+3  A: 

There is a drawback to having a content type for logos, in that you will need to do two node loads for every page.

An alternative solution would be to implement a module which created a logo block. You could then tweak your theme to have a region where the logo is and put this block into the region. You could have whatever logic you want in the block. Including an admin interface if you so wish. This could be cached per user (and cleared once a day) so the overhead would just be a load of a block from cache rather than a node load. This also keeps presentation and logic separate, and I could imagine that a seasonal image module would be quite popular.

Jeremy French
+1  A: 

Just use a bit of raw php...

If your site uses normal url structure for languages you do something like this:

<?php
$path = drupal_get_path_alias($_GET['q']);
$path = explode('/', $path);
if ($path[0] == 'english') {
  $logolangclass = 'english';
};
?>

Then some regular date() stuff you could do something like this:

<?php 
$today = date("md");
if ($today == "1215") {
  $logoseasonclass = "christmas";
}
?>

Then use those two variables to build a css class for you logo like this:

<div id="MyLogo" class="<?php echo $logolangclass $logoseasonclass ?>"></div>

Which when rendered will produce something like this:

<div id="MyLogo" class="english christmas"></div>
robotoverlord
This would work, but the tricky part comes in with the logic, which i wanted a module to handle. I.e. to make users with no programming knowledge add logos, and that if logos overlap, that one with priority is chosen. e.g. if there is a christmas logo for the whole of december, and one for 10 december, that the one for 10 december is shown on 10 december, and the one for christmas on all the other days.
RD
+1  A: 

This was a simple but effective solution, using cck and views:

Create a 'header pics' content type. Add fields for images, url, and 'show when' select list.

Images I used image upload with cropping module, constrained to 400px wide by 100px high to fit in header block.

'show when' select list I populated with summer, winter, fall, Halloween, Christmas, Veteran's Day, etc.

url is optional.

In view, filter by type = header_pic and show_when = whatever you want displayed now, limit = 1.

Need the Customfield PHP module addon for views, and add:

<?php
$temp = node_load($data->nid);
if ($data->node_data_field_header_pic_url_field_header_pic_url_url) { 
    echo '<a href="' . $data->node_data_field_header_pic_url_field_header_pic_url_url 
. '" title="' . $data->node_data_field_header_pic_url_field_header_pic_url_title 
.'"><img src="/' . $temp->field_header_image[0]['filepath'] . '" /></a>';
} 
else { 
    echo '<img src="/' . $temp->field_header_image[0]['filepath'] . '" />';
}
?>

Where the fields I've noted correlate to your actual fields.

What this does is wrap the image with that url field only if the url field is populated.

Then set the view in a block display, and set that block in the header region. Depending on theme, you may need to hack the page.tpl.php a little to move that header block region into the real header area (but once you get in there it's easy to see what you need to do).

You can even make a page view of this same view to display all of your great header images at once on a page (/headerpics), with an edit link by each for easy manageability.

This will work if you just want seasonal images. It's a simple form for non-technical users to upload and crop images. The only admin need is the occasional season (show when) changes in view filter.

Kirk Hings
This is actually what I ended up doing.
RD