0

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.

1 Answer 1

0

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>';
}
?>
6
  • 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) Oct 3, 2011 at 12:59
  • @TheDeadMedic I assume that $up_options->slideshow6 is the image SRC itself? Oct 3, 2011 at 13:01
  • $up_options->slideshow6 is the src, yes Oct 3, 2011 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> Oct 3, 2011 at 14:45
  • @ChipBennett My assumption was based on the code provided - Dean Elliot has enlightened the situation ;) Oct 3, 2011 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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