You can also define Theme Hook Suggestion. In this way, not only you can define css classes for the fields, but also display them in any html format. This is the way you should do it:
If the content type is for example CT
, in template.php
create YourThemeName_preprocess_node(&$variables)
function.
check the following condition:
if($variables['node']->type == "CT"){
}
In this way you check what the content type is. Now define the theme hook suggestion, like this:
if($variables['node']->type == "CT"){
$suggest = "page__node__CT";
$variables['theme_hook_suggestions'][] = $suggest;
}
create a file in the your theme directory next to the .info
file and rename it to page--node--CT.tpl.php
. to see it works, open this file in an editor and put this code:
<?php print "hello world";?>
Clear the cache and open a node of CT
content type to see if it prints hello world
in the region of $page['content']
of page.tpl.php
Now install entity module. Suppose the fields of CT
content type is field_CT_field1
and field_CT_field2
, then write :
if($variables['node']->type == "CT"){
$suggest = "page__node__CT";
$variables['theme_hook_suggestions'][] = $suggest;
$wrapper = entity_metadata_wrapper('node',$variables['node']);
$variables['field1'] = $wrapper->field_CT_field1->value();
$variables['field2'] = $wrapper->field_CT_field2->value();
}
Now in page--node--CT.tpl.php
you can use $field1
and $field2
as the value of the node fields and put them in any html element and assign them any css class.