カテゴリーごとにスタイルシートを替えたい【WPハック】
カテゴリー別にデザインを替えたいときのwordpressハック。
ハックというほどのもんでもないのですが、備忘録的にポストします。
通常wordpressではスタイルシートは下記のように記述します。これが、ほぼデフォルトの設定のはず。
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
替えたいカテゴリーごとにスタイルシートを用意して、このコードの条件によって分岐させています。
header.phpのスタイルシートの呼び込みを書き換えてください。
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/blue.css" type="text/css" media="screen,projection" />
<?php
if( in_category( 1 ) )
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/blue.css" type="text/css" media="screen" />
<?php } elseif ( in_category (2) )
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/yellow.css" type="text/css" media="screen" />
<?php } elseif ( in_category (33) )
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/black.css" type="text/css" media="screen" />
<?php } else { ?>
<?php } ?>
これでOK(のはず・・・:-p)
ネタ元:WPSHOUT
関連する記事
以下の記事が関連がありそうです。Facebook comments:
Leave a Reply
※コメントが認証されるまで、コメントは反映されません。


24 Responses so far.
Огромное вам пасибо! а еще посты на эту тему будут в будущем? Очень жду!
Спасибо. Я просто хотел писать на английском, вы можете ответить.
I’m a big fan of this blog and I check it regularly. Keep up the great work!
Beautiful stained glass.Thanks Comments:-)
That is nice to definitely find a site where the blogger knows what they are talking about.
Nice, just to let you know the post isnt showing up properly on my iphone – I think there is a plugin you can grab that takes care of that now.
you want on the iPhone display the blog? WP-Touch is good I think. It’s a nice plugin.
It’s always nice when you can not only be informed, but also entertained! I’m sure you had fun writing this article.Excellent entry! I’m been looking for topics as interesting as this. Looking forward to your next post.
Thank you. Good luck can provide good information to be posted.
I usually don’t ordinarily post on many another Blogs, yet I just has to say thank you… keep up the amazing work. Ok regrettably its time to get to school.
Thank you for comment. Only useful? is nice.
I Will have to come back again when my class load lets up – nevertheless I am taking your RSS feed so I can read your site offline. Thanks.
I’d have to recognize with you here. Which is not something I usually do! I really like reading a post that will make people think. Also, thanks for allowing me to comment!
Thank you for comment. This blog is set up to help your glad…
You completed several fine points there. I did a search on the topic and found mainly people will consent with your blog.
What a great resource!
Exciting posting and a single which really should be more broadly identified about in my watch. Your level of detail is excellent and the clarity of writing is remarkable. I’ve bookmarked it for you personally in order that other people will likely be in a position to find out what you have to say.
If you are open to having a guest blog poster please reply and let me know. I will provide you with unique content for your blog, thanks.
Great information! I’ve been looking for something like this for a while now. Thanks!
Im glad to see this informative article. Thanks for such helpful and useful post.
Important information for me. Thanks for really competent informative article. Ill be in touch with U
I found here something new and interesting. Thanks
First of all I care for the quality of your post. That was interesting to read and helpful article. And Im lookin’ forward to see your next thinks.