2012-06-28 52 views
0

取決於你在該網站中的哪些部分,我服務於WordPress的不同的頁眉的孫子,「住宅」,「商業」或其他使用下面的代碼:WordPress的如果兒童與頁

<?php 
    /* 
    Template Name: Package 
    */ 
    if (is_page('business') || $post->post_parent == "17") 
    { 
     get_header('business'); 
    } 
    else if (is_page('residential') || $post->post_parent == "19") 
    { 
     get_header('residential'); 
    } 
    else 
    { 
     get_header(); 
    } 
?> 

儘管我需要將它擴展到與孫子們一起工作,所以再往下一級。有人有想法嗎?

回答

0

你可以檢查,看看是否該頁面與您指定作爲頂級父ID的祖先,即

if(in_array('19', get_ancestors($post->ID, 'page')){...} 
0

伊夫以類似的方式,你如何編碼的最初做過,但是我只是改變該類並使用css來調用該類的圖像。