I am designing a theme where every page has a different text, background and other elements’ color. I was able to style every single page (and post category related) with these:
<?php if ( is_home() || is_search() || is_archive ())
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/home.css" type="text/css" media="screen" />
<?php } elseif( is_category( 'Turismo a Bra' ) || is_page('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('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'))
{
?>
<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'))
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/enogastronomia.css" type="text/css" media="screen" />
<?php } elseif ( is_category ('Natura')|| is_page('Natura'))
{
?>
<link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/natura.css" type="text/css" media="screen" />
<?php } else { ?>
<?php } ?>
The problem comes when I have (and i have a lot) of subpages. I want them to be styled as their parents. I though that WP had the is_sub_page(#), but no luck.
Do you know what I should add in the condition to make header understand when it is dealing with a subpage and, in that case, get the ID of the parent and based on that style the page.
I am a novice with php and wordpress, it makes sense in my head, but i dont know how to phrase it.
Thanks a lot, an example is here(the subpages are in the upper right side.
To check whether the post decends from a page with a certain category or page title then you could get its parent and check, eg:
As you already have a lot of code and you are doing this multiple times it may be best to encapsulate your entire check within a function:
So your code would look something like: