Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

uploading more than one background image

l have this code below in plugin to select a background for the panels in the accordion but wanting to tweak so that it selects more than one image for one background. l have the following code but now working. any idea how to remedy this please?

protected function create_background_image() {
        $background_source = $this->lazy_loading === true ? ' src="' . plugins_url( 'accordion-slider-lite/public/assets/css/images/blank.gif' ) . '" data-src="' . esc_attr( $this->data['background_source'] ) . '"' : ' src="' . esc_attr( $this->data['background_source'] ) . '"';
        $background_alt = isset( $this->data['background_alt'] ) && $this->data['background_alt'] !== '' ? ' alt="' . esc_attr( $this->data['background_alt'] ) . '"' : '';
        $background_title = isset( $this->data['background_title'] ) && $this->data['background_title'] !== '' ? ' title="' . esc_attr( $this->data['background_title'] ) . '"' : '';
        $background_width = isset( $this->data['background_width'] ) && $this->data['background_width'] != 0 ? ' width="' . esc_attr( $this->data['background_width'] ) . '"' : '';
        $background_height = isset( $this->data['background_height'] ) && $this->data['background_height'] != 0 ? ' height="' . esc_attr( $this->data['background_height'] ) . '"' : '';

        $classes = "as-background";

        $background_image = '<img class="' . $classes . '"' . $background_source . $background_alt . $background_title . $background_width . $background_height . ' />';

        return $background_image;
    }

1 Answer

HTML img tags can only have one src attribute, and only one value for that attribute, i.e. only one image.

There is the new srcset attribute that can allow different versions of an image (mainly used for 'responsive images'), but browser support is... not great.

Otherwise you might have to change the entire thing to use a different element, such as a div, and then you can actually use multiple backgrounds with CSS.

Treehouse has a quick tip video on how to achieve that with CSS: Multiple Background Images with CSS