0
votes

Drupal 7 and Drupal 6 In page or story content type for example there are two basic field called title and body. Is it possible to define a custom css class for title or / and body field, when ever we create new content.

for example some times we might need a title in red, some times in blue or orange etc... so when ever we are creating a content we can define that the title of this specific node will use .red class

2

2 Answers

2
votes

You can create a CCK textfield (e.g. field_title_class), and then use it in your theme's node.tpl.php. if your original was like this (taken from Garland theme):

<?php if ($page == 0): ?>
  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>

You can change it to:

<?php if ($page == 0): ?>
  <h2<?php print empty($node->field_title_class[0]['value']) ? '' : (' class="' . $node->field_title_class[0]['value'] . '"'); ?>><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>

this would check if there's a value in field_title_class and if there is, will print the class.

0
votes

You can use body classes in your template http://batayneh.me/post/power-drupal-body-classes-theming
You can also use node classes module for drupal 6 http://drupal.org/project/node_class