.. well i persevered. I don’t know if this is the most elegant method but this is what i have done:
1. I created a function called get_page_template_name() based on get_page_template() out of functions.php.
it returns the file name (without the full path and without the .php extension) of the template in use. e.g. if i have templates called MyTemplate.php and YourTemplate.php – it will return MyTemplate or YourTemplate respectively.
function get_page_template_name() {
global $wp_query;
$id = $wp_query->post->ID;
$template = get_post_meta($id, '_wp_page_template', true);
$template = substr($template,0,strlen($template)-4);
return apply_filters('page_template', $template);
}
2. I created n new templates that i can select when creating pages. In this case MyTemplate.php and YourTemplate.php
3. In my header.php that is used in all templates, I have this:
<div id="header" <?php if (get_page_template_name()!="") echo "class=\"".get_page_template_name()."\"";?>>
so it adds a class="MyTemplate" or a class="YourTemplate" or no class attribute at all.
4. In my CSS, I have added some additional classes as needed:
#header.MyTemplate {
background-image:url(/wordpress/images/top/MyTemplate.jpg);
}
#header.YourTemplate {
background-image:url(/wordpress/images/top/YourTemplate.jpg);
}
I hope this is useful for others. I would be interested to know if there is a more elegant way of doing ths.
regards
Glyn