A quick&dirty taxonomy based css loader

I had to implement a multiple colored theme for one of our sites. The site is a small company site with few static pages and a gallery. I know that there are several modules that can implement this feature, but I didn't want to install extra modules. So I added following few lines to the template.php file from my zen-based theme:
<?php
/**
* This function includes a css file based on the selected taxonomy terms.
* With this, the submitter can assign extra css for the site.
* @param $vid the vid of the taxonomy
*/
function _taxonomy_based_css_loader($vid){
$nid = null;
if (arg(0) == 'node' && is_numeric(arg(1)))
$nid = arg(1);
else return;
$node = node_load($nid);
if(isset($node->taxonomy))
foreach($node->taxonomy as $t)
if($t->vid == $vid)
drupal_add_css(path_to_theme() . '/'
. $t->name . '.css');
}
This a very tiny but powerful function. All you have to do is to create a vocabulary, and assign some terms for it. After that create some css files with the terms' name in your theme folder. Finally add this function to your template.php file, and call it with the vid of the theme-changer vocabulary. Enjoy :)









I think you could also do this in a themes template.php phptemplate_variables() because you already have the node object.