2013-08-16 111 views
0

我使用下面的代碼來顯示特定的標題圖片取決於觀衆什麼是網頁或類別:如何顯示一個獨特的標題圖片博客類別和子類別中的WordPress

<!-- Custom Design masthead --> 
<?php if (is_page(259)) { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/masthead-1.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

<!-- About and sub-pages masthead --> 
<?php } elseif (is_page(array(245,348,352,357,325))) { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/masthead-2.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

<!-- Design Community masthead --> 
<?php } elseif (is_page(array(365,568))) { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/masthead-3.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

<!-- Contact and Privacy masthead --> 
<?php } elseif (is_page(array(264,330))) { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/masthead-4.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

<!-- Blog masthead --> 
<?php } elseif (is_category(4)) { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/masthead-5.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

<?php } else { ?> 
<?php bloginfo('template_directory'); ?>/images/masthead-0.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

<?php }?> 

到目前爲止,太好了。我遇到的問題是如何修改以下語句:

<!-- Blog masthead --> 
<?php } elseif (is_category(4)) { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/masthead-5.jpg" width="1140" height="250" alt="Custom Acrylic Furniture" /> 

以便它包含類別和任何子類別。

任何幫助表示讚賞!

回答

0

您需要獲取當前類別的子類別,如 $ this_cat =(get_query_var('cat'))? get_query_var('cat'):1; wp_list_categories('child_of ='。$ this_cat。');

之後,您需要應用條件。

相關問題