Use Taxonomy Term slug to populate taxonomy.php (2 posts)

  1. psnepsts
    Posted 4 years ago #

    Hello all,

    I feel a touch sleazy with this post, as I feel like I should know how to do this!

    I've dug around and managed to mangle together the following bit of code:

    	$term =	$wp_query->queried_object;
    	$tempDirectory = get_bloginfo('template_directory');
           echo '<img src="'.$tempDirectory.'/images/specialties-'.$term->slug.'.png" width="1015" height="327" alt="Specialties: '.$term->name.'" />'; ?>

    This is placed in my taxonomy.php page. It uses the current taxonomy term's slug to pull in the correct image associated with that term, and uses the name to populate the alt="" value. Works great.

    What I'd like to to is make this conditional such that if the image requested does not exist, display a default image instead.

    Anyone have ideas on how to build this if else?

  2. thirstcard
    Posted 4 years ago #

    <?php if (is_tax( 'TAXONOMYNAME' )) { ?>
    //do something if taxonomy exists
    <?php } else { ?> 
    //do something if taxonomy does not exist
    <?php } ?>

    This code will check if your taxonomy exists but I know that isn't exactly what you're asking. You could possibly have the image stored as an attachment and then check if an attachment exists? Just an idea

Topic Closed

This topic has been closed to new replies.

About this Topic