Hi all,

I'm using Drupal 5.1. I've implemented node-my_contenttype_1.tpl.php, and it works fine. Just one thing, though. I would like to put something (i.e. a picture) before (or actually: above) the node title. I would like to this for my_contenttype_1, but Not for my_contenttype_2.

Could anyone point me in the right direction?
Or more in general: how can I influence the appearance of a node's title, add something to it etc.?

Thanks!

Ludo

Comments

Anonymous’s picture

Ludo,

This may not be the best way, but it's what worked for me. I have a content type "storyandimage" with an imagefield on it. I use an imagecache setting called "content" that scales the image to the width of my grid.

I created this block:

if ((arg(0) == 'node') and (is_numeric(arg(1)))) {
  $nid = arg(1);
  $node = node_load($nid);
  $image = $node->field_useimage[0];
  if ($image) {
    print theme('imagecache', 'content', $image['filepath'], $image['alt'], $image['title'], NULL);
  }
}

I added it to a region of my template called "content top" which is printed out before the title and content of the page. Then I set the visibility properties of the block to only show on the right nodes and pages. That will be specific to your site.

I made the mistake of removing the title from my page.tpl and putting it in the node.tpl. That causes woe with the administrative interface at the very least, but also much more.

modul’s picture

Thanks for your explanation, Bangpound, and excuse me for saying this, but isn't this a textbook example of "overkill"?? I mean, I want to put a picture in front of my title, and apparently it involves a CCK field, imagecache, meddling with a region, block settings etc... Not exactly my idea of simplicity... Isn't there really anything else I can do to put a picture on top of my title, depending on which content type is active?? Once again, I thank you very much for the efforts of explaining this, but I do hope there is a simpler approach.

Ludo

Anonymous’s picture

Nevets gives a simpler approach for a static image. I assumed you were wanting to display an image that is somehow part of a node, either with image_attach or imagefield, so I misunderstood your issue. If you just want the same image to appear for every node of a particular type, by all means follow a different method.

I avoided putting such specific image handling code in my page template because I have several page templates and the block is easier to maintain.

nevets’s picture

Since you already have a node-my_contenttype_1.tpl.php file if you want the image when viewing the content in a list just add the approriate html for the image just before printing the title and inside the 'if' condition where the title is printed. You will want to include the image in a div as this will force the title to be on the next line.

If you want the image when just viewing the node you will need to modify page.tpl.php. Find the code that prints the title and agian inside the 'if' condition add some code. this time you will also need a test. Something like

<?php
if ( $node->type == 'your_content_type' ) {
  // Output html for image
}
?>