Support » Fixing WordPress » Use Taxonomy Term slug to populate taxonomy.php

  • 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:

    <?php
    	$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?

Viewing 1 replies (of 1 total)
  • <?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

Viewing 1 replies (of 1 total)
  • The topic ‘Use Taxonomy Term slug to populate taxonomy.php’ is closed to new replies.