need help with theming for Drupal 5.10
public
group: Vancouver
katy5289 - Tue, 2008-09-09 21:49
Hello everyone,
I need some advice on Theming for Drupal 5.10. My client has requested to have a unique photo in the header of each main content page. This is easy for an HTML site but how do I do this for a Drupal site?
The details:
It's a business brochure site max 10 pages with the basic content pages, Home, About Us, Services, Links, Contact Us.
So each page would have its own static photo in the header.
Thanks in advance for any help you can provide.
Katy :-)

Ical feed
conditional statements
Hi Katy,
One way is to add a conditional statement to your page.tpl.php. You can conditionally show an image based on node id or node type for example.
Something like this will check node type -
<?phpif ($node->type == 'your_content_type') {
print "<img src ... ";
}
?>
You can compare against anything that makes sense. I hope I'M making sense.
Great idea... How do you assign or test for content type?
The first site I built a few years ago required this type of treatment so I wrote a fairly elaborate conditional statement and more than likely wrote more code than necessary.... How do we assign or deal with values for $node->type?
If I print $node->type to the screen I get values like:
45page
46page
46book
53blog
4webblog
I also get some troubling results like:
-192 (For a content called webblog)
-196 (For the webblog reply ui page)
Are these values that you would expect to see?
EDIT: I just realized that I was looking at _menu_get_active_trail(); which gives me the unique number as well as $node->type which gives me page, book, webblog, blog, etc...
The trouble is that according to $node->type, all of my pages are "page" except for "blog" content and another type that I created called "webblog". I still get nothing for the index page for my new content called "webblog" and my sections and subsections are page.
I must be doing something wrong... Any thoughts?
I'd really like to help come up with a standardized approach to handling this issue as I have a couple of new sites coming up with the same requirement.
Cheers,
Andrew
A littel more insight.... Maybe :)
This might be a bit outlandish but this is what Ive been using:
<?phpfunction is_section()
{
$trail = _menu_get_active_trail();
$main = $trail[1];
switch(TRUE)
{
case ($main == 45):
$is_section = 'about';
break;
case ($main == 46):
$is_section = 'partner';
break;
case ($main == 47):
$is_section = 'grants';
break;
case ($main == 53):
$is_section = 'news';
break;
case ($main == -192):
$is_section = 'webblog';
break;
}
return $is_section;
}
?>
Then I can use:
<?phpif(is_section() == "about"){
$header_image = "/images/about_header.jpg";
}
?>
It's a bit of a hackish way of doing it so hopefully someone else has a better way.
Andrew
Unless the images are
Unless the images are updated on a regular basis the solution I've liked the best for this kind of thing is assigning a unique css id for each page and then using css to place the image on the page. I believe, but am not positive, that Raincity's base5 theme and the zen theme both assign unique id's to each page, so you can get code examples from there.
As a quick example, in your tpl.php file you'd have something like:
<div id="header-<?php print $node->nid ?>">// header stuff
</div>
Using a "make css safe" function you can use the $node->title and make the css id more readable.
A similar technique can be used for sections using either a cck field for designating sections, or examining the path.
nice!
I like that. Try to keep logic in your tpl's to a minimum.
I am using a 'Picture on the
I am using a 'Picture on the top of the page' block - mainly because my client wants to be able to set the pictures himself any time - different picture for different page. Following is the code I use:
// pictures - image file name
$pictures[1] = "picture1.jpg";
$pictures[2] = "picture2.jpg";
$pictures[3] = "picture3.jpg";
// ... as many as you want
// pages - relative url or alias in quotes separated by comma
$pages[1] = array("strengthenargument");
$pages[2] = array("node/97","groupwork","node","4-thesis-must-dos","groupdiscounts","notes-on-class-discussions");
$pages[3] = array("about","top-3-tips-for-most-important-skill","media","welcome-clubs","bio");
// ... as many as pictures
$alias = drupal_get_path_alias($_GET['q']);
$image_base_path = "/files/images/";
$image_file_name = "defaultPicture.jpg";
foreach ($pages as $i => $pagelist) {
if (in_array($alias, $pagelist)) {
$image_file_name = $pictures[$i];
}
}
if($image_file_name) {
print "<img src=\"" . $image_base_path . $image_file_name . "\" />";
}
Blocks might help
define one block for each header required and set the visibility appropriately. Advantages
A Generic Way to Deal With such Issue
Hi,
I have another way to deal with such issue. As a programmer, I think this way is a little bit more generic. But I'm not sure whether it is working for Drupal 5 since I touched Drupal from version 6 and never went through the details of Drupal 5's code.
You may create a new content type called 'New Page', for example, and add one field, 'field_header_image', whose possible values are 'home.png', 'about.png', 'services.png', and etc. You may probably make this field invisible from anonymous and normal users. Thus, when you create a new page, you need to set this field. When rendering a page of such type, the variable $node->field_header_image[0]['value'] contains the value of 'field_header_image'.
In the page template file, 'page.tpl.php', you just need to
set the header image name at the top
<?phpif (isset($node->field_header_image[0]['value'])) {
$_this_header_image = $node->field_header_image[0]['value'];
}
else { // make sure the header image set
$_this_header_image = 'common.png';
}
?>
add the img tag of the header images in a proper position,
<?phpecho 'img src="some_path/'.$_this_header_image.'" alt="" />';
?>
I have tested this way under Drupal 6 and I guess it will also work with Drupal 5 but the variable name, i.e., '$node->field_header_image[0]['value']', may be different. To get the exact name, you could dump '$node' to find it.
Cheers,
Steve
need to have client upload new photos
Thank you Steve,
I would like to make it so that the cient will be able to upload new photos for the headers.
Would this be possible with this new Content Type? I'm new to CCK and Views.
Katy :-)
Yes Katy, you just need to
Yes Katy, you just need to ask them to keep the same image name for each page.
Cheers,
TS
or using cck imagefields,
or using cck imagefields, you could create a block view with the image, put the block in the appropriate region.