How to Theme Nodes of Specific Content Type in Drupal 7

There are Basically 2 ways to Theme a page in Drupal
i) By using theme functions in modules
ii) By creating template files in the theme directory.

For the Designer creating the template file would be much more convenient to theme than using the theme function.

Sometimes there may be a need to theme node pages based on content type. In such cases we need to create a template file and create unique styles for that particular node type.

Step 1: If you are using a content type called yourcontenttype, create a template file called node — yourcontenttype.tpl.php and place it in your current theme directory. Say for example suppose if you want to theme blog nodes your filename would be node–blog.tpl.php. Note the two hyphens between node and yourcontenttype is the convention used in Drupal 7

Step 2: Now the Next Step would be to identify the node elements and surround it with your div classes. If you are not sure about the variables copy the contents of node.tpl.php file and paste in your template file.

Step 3: If you dont want to copy node.tpl.php and want to write the template file unique, follow this step.

To Render Different elements in your template file refer the below syntax

Node Title —

Node Body — – Will Print all the content including images

Node Custom field —

— Here yourfieldname is the machine name of your custom field.

Node Image —

Step 4: If you want to Hide any elements in the content section such as comments use the below statement
before

Step 5: Suppose if you want to show only if the custom field has a value you can use the below statement


Requirement :- Drupal 7