Custom Drupal theme

Posted by
  1. Copy the existing node.tpl.php file (if you only want to move a few things around) and rename it to node-custom.tpl.php, the “custom” part is the machine readable name you gave your node.
    For example: a blog entry would be node-blog.tpl.php
  2. The other way is to simply make a new text file on your computer and name it node.tpl.php, this will give you a completely blank canvas to work with.

Once you have your new file made, put this piece of code at the bottom or if you started new then simply paste this code into your node-custom.tpl.php:

<?php print_r($node) ?>

Either just save your file or upload it to your ftp, depending on how you are working on your site.
Refresh your browser on the dummy node entry you made earlier. Notice now that after your content a bunch of other stuff now shows up. That is what we will be referencing later.

To use the code that is displayed on your node entry properly you must understand what it is doing.
These are php functions that we will call to our template and then manipulate to our hearts desire. Lets take a simple piece to start out with. I’ve set up a demo node with a node-demo.tpl.php you can find HERE. In the node-demo.tpl.php file, all I have printed is

<?php print_r($node) ?>

The text in the [brackets] are the functions that we are going to be using.
Starting off with something simple:

<?php print $node->content ?>

I want you to notice a few things here all the php coding we will be doing will all include:

<?php print ?>

We are simply printing the desired functions. The next part $node is referencing that we are working with a node type. and finally notice that the first level of the function isn’t in [brackets]. If you use the rest of the function they will need to be enclosed in [brackets] like this:

<?php print $node->content ['body']['#value']?>

Make sure you use ‘apostrophes‘ around the text in the [brackets], unless it is a number.

If I wanted to print the custom cck text field I made for the node. I first find the [field_custom], that is the machine readable name I made when setting up the cck field for the node. Note that there are actually two of these, you want to find the one that is not under the [content]. Then I find either the array above the final function or the final function itself. In this case I find the array [0]. Then I find the final function [value].

Now you put the php code together like this:

<?php print $node->field_custom[0]['value'] ?>