---
url: 'https://dxpr.com/drupal-blog/theming-cck-node'
title: 'Theming a CCK Node'
author:
  name: Jurriaan
  url: 'https://dxpr.com/users/jurriaan'
date: '2023-11-13T17:20:37+00:00'
updated: '2023-11-13T17:21:41+00:00'
copyright: 'Copyright DXPR. All rights reserved.'
type: blog
summary: "It's easy to create a custom node with CCK, but what if we want to change how the node looks by default? It's a step up from theming your submitted and your terms code, but it's not really that hard. The main difference between theming the CCK node and the regular node is that in node.tpl.php, we have several content sections within a node, so rather than just printing $content, we will print out parts of the content individually. I will use code from the wallpaper node type of this site for my examples."
tags:
  - 1.0.15
  - cck
  - node
  - node.tpl.php
  - planet
  - theming
published: true
schema:
  '@context': 'https://schema.org'
  '@graph':
    -
      '@type': BlogPosting
      headline: 'Theming a CCK Node'
      description: "It's easy to create a custom node with CCK, but what if we want to change how the node looks by default? It's a step up from theming your submitted and your terms code, but it's not really that hard. The main difference between theming the CCK node and the regular node is that in node.tpl.php, we have several content sections within a node, so rather than just printing $content, we will print out parts of the content individually. I will use code from the wallpaper node type of this site for my examples."
      about:
        - cck
        - node
        - node.tpl.php
        - planet
        - theming
      datePublished: '2023-11-13T17:20:37+0000'
      dateModified: '2023-11-13T17:21:41+0000'
      publisher:
        '@type': Organization
        '@id': 'https://dxpr.com/#organization'
        name: DXPR
        url: 'https://dxpr.com/'
        logo:
          '@type': ImageObject
          url: 'https://dxpr.com/themes/custom/dxpr_com/dxpr-logo-dark.svg'
          width: '1348'
          height: '501'
      mainEntityOfPage: 'https://dxpr.com/drupal-blog/theming-cck-node'
    -
      '@type': WebPage
      '@id': 'https://dxpr.com/drupal-blog/theming-cck-node'
      description: "It's easy to create a custom node with CCK, but what if we want to change how the node looks by default? It's a step up from theming your submitted and your terms code, but it's not really that hard. The main difference between theming the CCK node and the regular node is that in node.tpl.php, we have several content sections within a node, so rather than just printing $content, we will print out parts of the content individually. I will use code from the wallpaper node type of this site for my examples."
      publisher:
        '@type': Organization
        '@id': 'https://dxpr.com/#organization'
        name: DXPR
      inLanguage: en
---
[Blog](/blog) / Theming a CCK Node # Theming a CCK Node

   **Jurriaan** 13 November 2023

 It's easy to create a custom node with CCK, but what if we want to change how the node looks by default? It's a step up from theming your *submitted* and your *terms* code, but it's not really that hard. The main difference between theming the CCK node and the regular node is that in node.tpl.php, we have several content sections within a node, so rather than just printing *$content*, we will print out parts of the content individually. I will use code from the wallpaper node type of this site for my examples.

 Step 0, before we get to the phptemplate part of this tutorial, you have to think to yourself if you really need to theme a specific node programmatically. In many cases, you can style a node just fine with CSS only, so first imagine how you want to theme your node and determine if you really need to get into the templating engine.

 Subsequently, we need to create a template file for our node type, make a copy of your themes node.tpl.php and rename it node-*typename*.tpl.php. In the case of my wallpaper node on this site that will be node-dwall.tpl.php.

 Next we will learn how to identify and print parts of our node. Rather than $content, we're now working with $node, this is the object that holds all our node its content. To find out what our node object contains we will use the print\_r function:

`	<pre style="background:#eee;border:1px solid black;clear:both;"><font color="#000000"><font color="#0000BB"><?php print_r</font><font color="#007700">(</font><font color="#0000BB">$node</font><font color="#007700">) </font><font color="#0000BB">?></font></font></pre>`

 If you check out your node page with the above snippet in place you will find it displays (nearly) all the node data you could wish for. The most interesting parts of our nodes are of course our node fields. This is what a field could look like when printed by print\_r:

`    [field_fullsizewall] => Array<br></br>        (<br></br>            [0] => Array<br></br>                (<br></br>                    [fid] => 73<br></br>                    [title] => drupal3d.jpg<br></br>                    [alt] => drupal3d.jpg<br></br>                    [nid] => 31<br></br>                    [filename] => drupal3d.jpg<br></br>                    [filepath] => files/wallpapers/drupal3d.jpg<br></br>                    [filemime] => image/jpeg<br></br>                    [filesize] => 56360<br></br>                    [view] => [actual image here]<br></br>                )<br></br><br></br>        )`

 The above snippet displays all the data from my wallpaper file. Each of these pieces of data can be printed out using the following syntax:

`print $field_name-of-field[0]['name-of-field-particle'];`

 So that's really all there is to it, you find the piece of data you want to use, and you blend it in with your html. There is really no limit to what you can do with your node, you can use the data to create a little google map with each node, if you have location data. You could arrange field data in complex layouts, with tables or definition lists, or you can keep it simple and just print out the fields with some extra structural HTML to use as hooks in order to decorate the node with CSS.

 As always, I will please the lazy drupal user who just wants to copy paste and play with the code, which is in fact the best way to learn. The following code is my entire node-dwall.tpl.php file that I currently use on this site, including the print\_r stuff, wrapped in an if test that makes sure only the admin gets the array layed out beneath the actual node.

 You should see the content part of the node file as 2 parts, the teaser part and the full-view part. I check with $page==0 to see if we want to display just a teaser or the whole thing, so the first part after if $page == is what I want to display as teaser and the part after 'else {' is what we display in in full node view, which is [this page](/wallpapers/3d-druplicon.html). I'm using [imagecache](http://www.drupal.org/project/imagecache/) to create resized derivatives of the file that was uploaded with the node form. If you want to use my imagecache code below on your site you will probably need to remove all the /system parts in the urls, as this requests the file through the *private files ystem*, and with imagecache you should use the public files ystem unless you have a good reason not to.

`  <div class="node wallpaper<font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$sticky</font><font color="#007700">) { print </font><font color="#DD0000">" sticky"</font><font color="#007700">; } </font><font color="#0000BB">?></font></font><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (!</font><font color="#0000BB">$status</font><font color="#007700">) { print </font><font color="#DD0000">" node-unpublished"</font><font color="#007700">; } </font><font color="#0000BB">?></font></font>"><br></br>    <font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$picture</font><font color="#007700">) {<br></br>      print </font><font color="#0000BB">$picture</font><font color="#007700">;<br></br>    }</font><font color="#0000BB">?></font></font><br></br>    <div class="content"><br></br>		<font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$page </font><font color="#007700">== </font><font color="#0000BB">0</font><font color="#007700">) {</font><font color="#FF8000">// is 'teaser' </font><font color="#0000BB">?></font></font><br></br>		<font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="'</font><font color="#007700">.</font><font color="#0000BB">$node</font><font color="#007700">-></font><font color="#0000BB">path</font><font color="#007700">.</font><font color="#DD0000">'">'</font><font color="#007700">.</font><font color="#0000BB">theme</font><font color="#007700">(</font><font color="#DD0000">'imagecache'</font><font color="#007700">, </font><font color="#DD0000">'sidebarscreeni'</font><font color="#007700">, </font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">],</font><font color="#0000BB">$title</font><font color="#007700">,</font><font color="#DD0000">''</font><font color="#007700">,array(</font><font color="#DD0000">'class' </font><font color="#007700">=> </font><font color="#DD0000">'scrthumb'</font><font color="#007700">)).</font><font color="#DD0000">'</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font><br></br>		<font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">} else { </font><font color="#0000BB">?></font></font><br></br>		<font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#0000BB">theme</font><font color="#007700">(</font><font color="#DD0000">'imagecache'</font><font color="#007700">, </font><font color="#DD0000">'sidebarscreeni'</font><font color="#007700">, </font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">],</font><font color="#0000BB">$title</font><font color="#007700">,</font><font color="#DD0000">''</font><font color="#007700">,array(</font><font color="#DD0000">'class' </font><font color="#007700">=> </font><font color="#DD0000">'scrthumb'</font><font color="#007700">)); } </font><font color="#0000BB">?></font></font><br></br>		<font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">} </font><font color="#0000BB">?></font></font><br></br>		<ul class="resolutions"><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1024x768/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1024x768</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1152x864/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1152x864</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1280x960/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1280x960</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1280x1024/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1280x1024</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1600x1200/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1600x1200</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li>								<br></br>		</ul><br></br>		<br></br>		<ul class="resolutions widescreen"><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1280x800/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1280x800</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1440x900/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1440x900</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1680x1050/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1680x1050</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li><br></br>		<li><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">if (</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filepath'</font><font color="#007700">]) { print </font><font color="#DD0000">'<a target="_blank" title="'</font><font color="#007700">.</font><font color="#0000BB">$title</font><font color="#007700">.</font><font color="#DD0000">' screenshot" href="https://www.sooperthemes.com/system/files/imagecache/1920x1200/wallpapers/'</font><font color="#007700">.</font><font color="#0000BB">$field_fullsizewall</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'filename'</font><font color="#007700">].</font><font color="#DD0000">'"field_fullsizewall>'</font><font color="#007700">.</font><font color="#DD0000">'1920x1200</a>'</font><font color="#007700">; } </font><font color="#0000BB">?></font></font></li>								<br></br>		</ul>		<br></br>		</div><br></br>		<div class="links"><font color="#000000"><font color="#0000BB"><?php </font><font color="#007700">print </font><font color="#0000BB">$links?></font></font></div>				<br></br>  </div><br></br>	<font color="#000000"><font color="#0000BB"><?php <br></br>    </font><font color="#007700">Global </font><font color="#0000BB">$user</font><font color="#007700">;<br></br>    if (</font><font color="#0000BB">$user</font><font color="#007700">-></font><font color="#0000BB">uid </font><font color="#007700">== </font><font color="#0000BB">1</font><font color="#007700">) {<br></br>    </font><font color="#0000BB">?></font></font><br></br>	<pre style="background:#eee;border:1px solid black;clear:both;"><font color="#000000"><font color="#0000BB"><?php print_r</font><font color="#007700">(</font><font color="#0000BB">$node</font><font color="#007700">) </font><font color="#0000BB">?></font></font></pre><br></br>	<font color="#000000"><font color="#0000BB"><?php <br></br>    </font><font color="#007700">}<br></br>    </font><font color="#0000BB">?></font></font>	`

 <a class="a2a_button a2a_button_x"></a><a class="a2a_button a2a_button_linkedin"></a>