2012-01-07 12 views
1

私はすべてのページが異なるテキスト、背景、および他の要素の色を持つテーマをデザインしています。私が持っているときサブページはどのようにWordpressの親のスタイルを継承できますか?

<?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 } ?> 

問題が来る(と私はたくさん持っている)サブページのを:私はこれらをすべての単一のページ(および関連のポストカテゴリを)スタイルすることができました。私は彼らに彼らの両親のようなスタイルにして欲しい。私はWPがis_sub_page(#)を持っていましたが、運はありませんでした。

サブページを扱っているときにヘッダーを理解し、その場合は親のIDを取得し、そのスタイルに基づいてページを作成する条件を追加する必要があります。

私はphpとwordpressの初心者ですが、それは私の頭の中で意味がありますが、私はどのようにフレーズするのか分かりません。 、例が

おかげでたくさんあるhere(サブページは、右上にある。

答えて

1

はポストは、あなたがその親とのチェックを得ることができ、特定のカテゴリやページタイトルのページからdecendsかどうかを確認するには例えば:あなたはすでにコードの多くを持っていて、これを複数回行っていたよう

in_category('Turismo a Bra', $post->post_parent) 

それは関数内であなたの全体のチェックをカプセル化するために最善のことがあります

function needs_style($style, $the_post){ 
    $needs_style = false; 
    //check details of this post first 
    if($the_post->post_title == $style){  //does the same as in_page() 
     $needs_style = true; 
    } 
    elseif(in_category($style, $the_post)){ 
     $needs_style = true; 
    } 
    //otherwise check parent if post has one - this is done recursively 
    elseif($the_post->post_parent){ 
     $the_parent = get_post($the_post->post_parent); 
     $needs_style = needs_style($style, $the_parent); 
    } 
    return $needs_style; 
} 

あなたのコードは次のようになります:

if (is_home() || is_search() || is_archive()) { 
    //set stylesheet 
} 
elseif(needs_style('Turismo a Bra', $post)) { 
    //set stylesheet 
} 
elseif(needs_style('Eventi', $post)) { 
    //set stylesheet 
} 
+1

DUDE!できます!本当にありがとう! –

関連する問題