Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created March 14, 2009 12:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save beastaugh/79060 to your computer and use it in GitHub Desktop.
Per-category stylesheets plugin for WordPress
<?php
/*
Plugin Name: Category Stylesheets
Plugin URI: http://extralogical.net/projects/
Description: Apply category-specific stylesheets to posts and archives.
Author: Ben Eastaugh
Version: 1.0
Author URI: http://extralogical.net/
*/
function category_stylesheet_link() {
if (is_single()) {
$cats = array();
$cat_objs = get_the_category(get_the_ID());
foreach ($cat_objs as $cat)
array_push($cats, $cat->cat_ID);
} elseif (is_category()) {
$cats = array(get_query_var('cat'));
}
if (!isset($cats) || empty($cats)) return;
foreach ($cats as $cat_ID)
printf('<link rel="stylesheet" type="text/css" href="%s" />' . "\n",
get_bloginfo('stylesheet_directory') .
'/category-' . $cat_ID . '.css');
}
add_action('wp_head', 'category_stylesheet_link');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment