What i am trying to do is call different CSS (for background and other elements) based on the category the post is. It should be very easy, and worked for the pages, but for some reasons it doesn’t want to work for categories.
Here is the code I have:
<?php
if( is_page('Turismo a Bra') || is_page_template( 'turismo.php' ) || is_category('Turismo a Bra') )
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/turismo-a-bra.css" type="text/css" media="screen" />
<?php } elseif ( is_category ('Eventi') || is_page_template( 'eventi.php' ) || is_page_template( 'eventi.php' ) || is_category('Eventi') )
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/eventi.css" type="text/css" media="screen" />
<?php } elseif ( is_category ('Arte e Cultura') || is_page('Arte e Cultura') || is_page_template( 'arte.php' ) || is_category('Arte e Cultura'))
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/arte-e-cultura.css" type="text/css" media="screen" />
<?php } elseif ( is_category ('Enogastronomia')|| is_page('Enogastronomia') || is_page_template( 'enogastronomia.php' ) || is_category('Enogastronomia'))
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/enogastronomia.css" type="text/css" media="screen" />
<?php } elseif ( is_category ('Natura')|| is_page('Natura') || is_page_template( 'natura.php' ) || is_category('Natura'))
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/natura.css" type="text/css" media="screen" />
<?php } else { ?>
<?php } ?>
As I said, worked perfectly for the page template and the actual page, but not for the categories. I m sur it is very easy, can anybody help me?
I believe you are using the wrong method to check category:
According to the wordpress documentation you use
is_category()for archive pages (WP Function Reference/is category)To check current posts you use
in_category()(WP Function Reference/in category)