


This article explains how you can use CCK variables to customise each of your nodes. You will need FTP access to your server and to know the basic workings of the CCK module.
In this example we will work with a content type for a "News Item" - the machine readable name for this will be "news". It has the following fields:
Label: Title
Label: Body
Label: Teaser - Type: field_teaser
Label: Image - Type: field_fullimage
Label: URL - Type field_url
If we use the following fields, then we want to be able to style the look of our news item page. To do this we first create a file in our current themes directory.
NOTE: you have to call the file by the machine readable name of your CCK content type. We mentioned before that our "News Item" had a machine readable name of "news" therefore we call the file "news-node.tpl.php".
Now we need to enter our fields into our blank template page we have created. This will allow us to customise the output used on any of our News Item nodes.
First, we will display the title of the News Item in <h2> tags so they are second level headings. For this we enter
<h2><?php print $title ?></h2>
We can output the picture using:
<?php print $node->field_image[0]['view']; ?>
There are other ways to print out these images, such as:
<?php print $node->field_image[0]['filepath']; // this prints out url to the original image ?>
<?php print $node->field_fullimage[0]['filename']; // this prints out imagecached version ?>
Next we will want to print out the text in the "Body" using:
<?php print $node->content['body']['#value']; ?>
Finally, we can enter a URL - which could link to a relevant source of information - connected to the news item. We can now check whether a URL has been entered, if it has, we will link it with a "Read more" link.s
<?php $url = $node->field_url[0]['value'];
if(!empty($url)) { ?>
<p>Read More about <a href="<?php print $node->field_url[0]['value']; ?>"><?php print $title ?></a></p>
<?php } ?>
Save and upload your file. You page should now represent the templated objects from your tpl file.
Post new comment