In Drupal 5/Drupal 6 with CCK module installed and activated, you just define your content type, then create a node-content_type.tpl.php file to render the nodes for that content (replace "content_type" in the filename by the "machine readable" content type name you gave while creating the type).
To access your customized fields within the template using
<?php
print $fieldname[0][view];
?>
where fieldname is the "machine readable" fielde name you provided while creating the field.
To display the title of the page, use
<?php
print $title;
?>
To display body of the page, use
<?php
print $node->content['body']['#view'];
?>
========
What I did
1. I created a comstom type called "student-admin' type node.
2. I created a file called "node-student_admin.tpl.php" under the theme.
3. This is a part of the conents of my "node-student_admin.tpl.php"
--------------
<table border=1>
<tr>
<td><strong>Day of Birht: </strong><?php print $node->field_birthday[0]['view'] ?></td>
<td><strong>Gender: </strong><?php print $node->field_gender[0]['view'] ?></td>
<td><strong>Marital Status: </strong><?php print $node->field_marital_status[0]['view'] ?></td>
<td><strong>Country: </strong><?php print $node->field_country[0]['view'] ?></td>
</tr>
<tr>
<td><strong>Mobile: </strong><?php print $node->field_mobile[0]['view'] ?></td>
<td><strong>Fax: </strong><?php print $node->field_fax[0]['view'] ?></td>
<td><strong>Email: </strong><?php print $node->field_email[0]['view'] ?></td>
</tr>
</table>
The outcome looks like this:
| Day of Birht: 1981 |
Gender: Male |
Marital Status: Single |
Country: China |
| Mobile: 0123-456789 |
Fax: 99999999 |
Email: email@address.com |
If you use table head th in the first row, it will looks like this
<table border=1>
<tr>
<th>Day of Birht</th>
<th>Gender</th>
<th>Marital Status</th>
<th>Country</th>
</tr>
<tr>
<td><?php print $node->field_birthday[0]['view'] ?></td>
<td><?php print $node->field_gender[0]['view'] ?></td>
<td><?php print $node->field_marrage[0]['view'] ?></td>
<td><?php print $node->field_country[0]['view'] ?></td>
</tr>
</table>
| Day of Birht |
Gender |
Marital Status |
Country |
| 1981 |
Male |
Single |
China |
How to display CCK inline?
Sample code added to style.css
.field-field-gallery div { margin-right: 20px; display:inline; }
For Drupal 7
One needs to change
<?php print $node->field_name['und'][0]['value'] ?>
Also see here:
http://drupal.org/node/1089656
Marinelli theme
This is exactly what I am looking for. I am trying to use this in Marinelli theme and created the node-content_type.tpl.php file. Where do I need to insert the table? It seem that the content is displayed by
<?phpprint $content
?>
Can you tell me how/where I insert the table at the top of my content?
Thanks, as you note I'm a newbie in this area :-)
Computed field
This is really helpful for what I'm trying to do but I don't want to update node tpl file and instead, I only want to display CCK fieldgroup or only few fields in table format. I tried using computed field but it didn't work.
Thanks,
kb
Typo
Birht ->Birth