Add css-file to single-post-template based on category
<p>Im using this function (in <code>function.php</code>) to add a template for specific category slug, however I also wish to use a specific css-file, however I don't know how to embed it correctly in the filter. I tried below, but this just renders a blank page (so php-error), thankful for any help:</p>

<p>Original code, which enables templates for post categories to be created (i.e. "single-categoryname.php") in Function.php:</p>

<pre><code>add_filter('single_template', create_function(
    '$the_template',
    'foreach( (array) get_the_category() as $cat ) {
        if ( file_exists(TEMPLATEPATH . "/single-{$cat-&gt;slug}.php") )
        return TEMPLATEPATH . "/single-{$cat-&gt;slug}.php";
        }
    return $the_template;' )
);
</code></pre>

<p>My failed atempt to include an external css:</p>

<pre><code>        add_filter('single_template', create_function(
            '$the_template',
            'foreach( (array) get_the_category() as $cat ) {
                if ( file_exists(TEMPLATEPATH . "/single-{$cat-&gt;slug}.php") )
                return TEMPLATEPATH . "/single-{$cat-&gt;slug}.php",

       //my code:
       wp_enqueue_style( 'single-{$cat-&gt;slug}', get_template_directory_uri() . '/css/single-{$cat-&gt;slug}.css', array(), '1.1', 'all');  
      }
            return $the_template;' )
      });
</code></pre>