Category specific CSS
-
Is it possible to assign different CSS files to different categories?
-
Anonymous
It is certainly possible to style each category in a different way – if I understand you correctly. It would not be necessary to have separate css files. If you wanted wholly separate files for some reason then you need a style switcher of some sort. Several have been posted here which would need to be adapted a bit.If you can let us know a bit more about where you are headed with this we might be able to assist. Sounds like you & your wife have an interesting project on the go.
How do you do it without CSS?
Since you read the other posts, then you know the basic idea – I would like to assign a category to a particular film she has made and then make it so that all the posts in this category had a unique “look” associated with that film. I thought CSS would be the easiest way to do this. I don’t want a user-run style switcher, I want to be the one controlling how it looks – accoring to each category.. (Actually, sub categories, since I’m using this feature in the latest nightly build – with all films listed under the “film category.”)AnonymousYou misunderstand me (my fault). If there was to be a style switcher it would need to be called onclick not by the user. However as I understand it we can style each category any way we want. We just need to identify the selectors correctly to go in the style sheet (bearing cross browser compatibility in mind of course). What we are actually doing of course is styling the posts. Then varying that style according to the category the post is in. As I understand the php post is a descendant child of category. I should say my own (under construction) WP CSS is so hacked I have lost track of what it should be like!
Thanks for explaining. This won’t work for me, since I want the whole site to look different depending on the category, not just the content of the post itself. For instance, if there is a banner photo and color scheme for the site, then each category would have a different banner photograph and matching color scheme.
I may actually need to have different templates for each category as well, although I’m not sure if this is possible. I would rather keep everything in one blog if possible, although I imagine I could also set up multiple blogs and link them together. I know this is possible in Nucleus, so I’m wondering if I shouldn’t just be using Nucleus instead of WordPress. The thing is, I find Nucleus’ templates very difficult to modify and edit to my needs. Looking at WordPress, it seems simpler. But maybe too simple for my needs…I think anon (no offense dude(ette?)) is making it more difficult than it needs to be.
I am going to make a few assumptions:
1) The main page will have some sort of default styleing (presumably by wp-layout.css).
2) Category = Movie
3) It would be the categories that have different looks, not the individual psots on the main page (regardless of the category they are in).
I would create a separate CSS file for each category/movie you want.
Then, in the index.php file, find the line where the CSS is imported. Should look like this:
@import url( <?php wp_siteurl(); ?>/wp-layout.css );
And replace it with something like this: (I think this will work)
<?if(single_cat_title(”, FALSE) != ”) {
echo “@import url( “.single_cat_title(”, FALSE) .” );”
}else{
echo “@import url( “.wp_stylesheet() .”/wp-layout.css );”
}
?>
Give you CSS files the same name as your category name, and it should work.
DISCLAIMER: This has not been tested, and I cannot guarantee that it will work. In theory it seems sound.
TGAnonymousThanks tech. We were kind of headed in that direction but your solution seems both elegant and timely. Let’s hope it works!
Yes – this looks like exactly the kind of thing I wanted. I’ll have to test it out. Ideally, if a category-specific style sheet doesn’t exist, I’d like it to revert to the default stylesheet.
I’m also worried about sub-categories. If a sub-category is films/name of film then does the way WP refers to this create problems for naming the file? I know slashes can be a problem for code.
I wish I was better at PHP code, but I’m only capable of tweaking code, not writing it myself.
Thanks!Actually, you may want to use category id’s instead of titles…otherwise, you couldn’t have category titles of more than one word. (I’ve always done this with specific id’s I’ve defined, rather than trying to use a category name or something.)
AnonymousThis is what I was thinking of. I’ve done something similar. It wasn’t immediately clear at the outset what was wanted. I wouldn’t think a default to a base css would be very pretty though for a film type site. Presumably though the add category (new film) instances will be infrequent. Nice thing is the css can develop
in parallel with the film artwork. (Posters, stills etc). It could be very cool.Thanks. These are great suggestions. I like being able to only specify those things I want to be “different” – and using category IDs should avoid problems with subcategories, etc. I’ll just add note markup to the CSS reminding me which IDs go with with categories. And this will allow me to add this stuff slowly. Right now I still need to work on the basic default look of the site.
<body id="<?=single_cat_title()?>">
totally works great!
thanks!
<body id="<?= $_GET['cat']?>">
This is great news… I’ll give it a try tonight.
I want to set up my site in a similar manner, with different blog pages for various projects I’m working on. I’d like each to have it’s own unique look (banner, colors and sidebar), and until this thread I thought I might have to set up completely separate blogs to do so.
Thanks!
Would anyone happen to have an updated method for the latest wordpress
I’m just trying to have different top banners for each category.
- The topic ‘Category specific CSS’ is closed to new replies.