2

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?

0

2 Answers 2

5

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
2
  • I agree about the hook_preprocess_node business.
    – electblake
    May 4, 2011 at 13:36
  • 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
1

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().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.