Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a slideshow in a custom theme I am developing and I am using the UpThemes Framework, what I want to know is, is there a way and image will only display if it has been defined?

For example, at the moment the max. number of images in the slideshow is 6, but if only 5 are uploaded the "alt" attribute displays for the 6th

For those unfamiliar with the framework, this is the PHP tag I am using

<?php echo $up_options->slideshow6; ?>

I have done this with custom fields in the past but I can't for the life of me figure out how I did it.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

If you're wanting to output based on the option being defined, then use isset(). e.g. this:

<?php echo $up_options->slideshow6; ?>

...becomes this:

<?php 
if ( isset( $up_options->slideshow6 ) ) {
    echo $up_options->slideshow6;
}
?>

EDIT

How would I get the following to appear only if "slideshow6" was defined <a href="#"><img src="<?php echo $up_options->slideshow1; ?>" alt="#"/></a>

I would go with:

<?php 
if ( isset( $up_options->slideshow6 ) ) {
    echo '<a href="#"><img src="' . $up_options->slideshow1 . '" alt="#"/></a>';
}
?>
share|improve this answer
    
Sounds like from the description that it is defined, but points to a non-existent image (i.e. a HTML <img /> string with a blank src) –  TheDeadMedic Oct 3 '11 at 12:59
    
@TheDeadMedic I assume that $up_options->slideshow6 is the image SRC itself? –  Chip Bennett Oct 3 '11 at 13:01
    
$up_options->slideshow6 is the src, yes –  Dean Elliott Oct 3 '11 at 14:38
    
Chip's code worked a treat, although I forgot to include the full line of code earlier. How would I get the following to appear only if "slideshow6" was defined <a href="#"><img src="<?php echo $up_options->slideshow1; ?>" alt="#"/></a> –  Dean Elliott Oct 3 '11 at 14:45
    
@ChipBennett My assumption was based on the code provided - Dean Elliot has enlightened the situation ;) –  TheDeadMedic Oct 3 '11 at 15:27
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.