Per-category stylesheets plugin for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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