如何在Wordpress中向博客类别和子类别显示唯一的标题图像

时间:2013-08-16 07:59:09

标签: wordpress conditional categories

我使用以下代码显示特定的标题图形,具体取决于查看者所在的页面或类别:

<!-- 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" />

以便它包含类别和任何子类别。

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您需要获取当前类别的子类别 $ this_cat =(get_query_var('cat'))? get_query_var('cat'):1;  wp_list_categories('child_of ='。$ this_cat。'');

之后你需要应用这些条件。