2012-01-07 6 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! 그것은 작동합니다! 정말 고마워! –

관련 문제