is_category()
如果要检查多个类别,请将数组作为参数。但通过检查现有文件,您可以更轻松地执行以下操作:
if ( is_category() )
{
$slug = get_queried_object()->slug;
$theme_path = "/images/slider_$slug.png";
$file = get_template_directory() . $theme_path;
if ( file_exists( $file ) )
{
echo \'<img src="\'
. get_template_directory_uri() . $theme_path
. \'" alt="" height="200px" width="960px" />\';
}
}