I want to attach a different CSS style to a node, basing on the node publishing date or some PHP properties.
What would be the best way to do this?
2 Answers
You are asking the wrong question. The question you should have asked is "how do I add a class on a node depending on some properties?". Using different set of CSS files to control styling a an element is just a no-no.
The answer to the correct question depends on whether you are targeting Drupal 6 or Drupal 7:
- On Drupal 6, you will generally have to implement the logic your own node template;
- On Drupal 7 (or on Drupal 6 if you are using an intelligent base theme like Zen), you would implement a
hook_preprocess_node()
in your theme and add classes to the'classes_array'
variable
-
-
You're right. I meant to say class. I'm using d6 so I guess i will have to just implement it on the template file May 5, 2011 at 1:34
Create a module, then in the
hook_init()
do your php calculations and include css with
drupal_add_css()
and js with
drupal_add_js().