开发者

drupal options of css classes for different fields in a content type

开发者 https://www.devze.com 2023-03-01 11:27 出处:网络
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 everwe

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 creat开发者_JS百科e 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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消