is_category()
takes an array as arguments if you want to check for more than one category. But you can make it even easier with a check for existing files:
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" />';
}
}
Related Posts:
- wp_enqueue_script adding conditional statement not working
- Check if first paragraph is an image, then show custom code right after it?
- If post author role is X
- Can a conditional statement apply to part of a slug?
- Add default content to posts in a specific category?
- is_front_page, is_page(‘slug’), is_page(id) not working
- Need help on creating If-statement for custom meta fields
- How to make gravatar.com avatars conditional?
- Loading Scripts on Specific Pages
- Condition function for is parent category?
- Conditional Statement – Best Way to Remove Nav on Contact Page
- Proper syntax for simple conditional bloginfo language
- wordpress is_page() problem
- Location-Based Content
- Personalized message for each unique password-protected page
- Conditional Shortcode image display
- Change Woocommerce order button page on particular page
- Change a url / link if a user is logged in?
- to create own conditional tags for business directory in wp
- How to use “Cases” instead of “IFs” for conditional logic
- Which is the better way to write a conditional statement? [closed]
- Nested conditionals
- Is there a way to password-protect part of a post?
- if/Else have_posts Else fails to echo message to page
- Conditonal statement for iPad
- Return function only on certain pages
- How to write this conditional statement?
- Conditional for Custom Post Types
- Date-Based Conditional Tag
- Message box when accessed from iPad
- Show this code if user has previously left a comment
- Insert a conditional in the middle of a function to give it 2 different outcomes
- How can I use ‘edit_form_after_title’ conditionally?
- Force Log in to view a page
- Conditional loading of CSS for my plugin
- Looks like this if condition is not working [closed]
- WP conditional site logo and header block
- How to know if the most recent article
- Widget logic conditional widget
- How to display image on condition that a selection has been made
- How to Conditionally Not Display a Link Based on Current URL?
- Allow users to only CREATE one single (custom) post
- If statement to check for post_content
- why is my custom loop failing?
- Conditional sidebar menu
- What is the best way to disable my WP website if the user has adblocker on? [closed]
- wp enqueue style on specific page templates
- Loading scripts only if a particular shortcode or widget is present
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- Show different different menu in theme_location depending on x
- meta content on required pages
- How to hide and content from auto-generated excerpts?
- Alternate text if shortcode returns no data
- Conditional Ajax inclusion
- How to do conditional publishing?
- A function like is_page() but returns true if on any sub page of given page
- Check to see if specific loop has less than certain amount of posts
- Get all children page ID’s including parent by title
- How do display simple page for printing product info? [closed]
- Duplicating Table of Contents for Paginated Post
- Plugin Code ONLY on Post Edit Page
- Prevent update of custom user profile meta field on the front end after 1st entry
- Condition display metabox in case the post is saved
- Conditional for a Single Post That Belongs to a Category?
- Conditionals if tags exist?
- Dynamically output a class to an anchor tag depending on what tag is chosen
- Conditional: IF post creation date is in the first half OR last half of the year [closed]
- FacetWP – conditionally display facet labels
- Check if sidebar is rendered?
- Why might conditionals not work on a page?
- NextGEN Conditional Statement [closed]
- Can I set up a hover animation in CSS depending on a PHP conditional?
- Multidimensional Array
- Conditional featured image with youtube thumbnail
- Banner appearing on Pages but not Posts; call it conditional confusion
- How to get type of archive whether it is post or date or category archive?
- Help with this custom field conditional if no field is set display nothing
- exclude custom post type from running a function
- Show image next to the comment author if have certain role
- How do I test whether [gallery] is empty?
- How to display conditional menus with Twenty-twenty two theme (and other new block themes)?
- can you help review CCCP (Conditional Cookie Content Post) and help to create a block?
- How do I make content only load on desktop? [duplicate]
- Modify wp-login.php Labels Conditionally Based On Referring URL
- Show code only on WooCommerce Pages
- Conditional Fields depending on checkboxes
- Conditional: IF current author’s custom post has a post thumbnail
- Understanding and using did_action() in a conditional statement
- Different titles for static, posts, and every xy page
- If Month=Particular month display content [closed]
- Php conditional help needed
- functions.php conditional output for a single plugin
- How do I add a nested conditional within an echo – to use a default image if there isn’t one in the post?
- Template tag for /page/# structure
- Create citation and url in post using 3 custom fields with conditions for each field… So close!
- Loop to pull content from parent element in custom post type [duplicate]
- A conditional button
- Weird html output of single_cat_title – is not inside of the html element?
- How to set up a echo? [closed]
- Conditional display based on ACF checkbox