wordpress theming - Get multiple images as background -
i'm trying wrap head around how implement multiple backgrounds (for slider) header.
i done customizer work , trying set things can let bit of javascript circle trough different background images set up.
header home page code (header-home.php) :
<header class="site-header"> <div class="row header-home" <?php if ((get_theme_mod('slider_radio', 'slider') == 'static')) { echo 'style="background-image:url(' . get_header_image() . ');' . 'background-repeat: no-repeat; background-position: center; background-size: cover;min-height:100vh">'; } else { echo 'style="background-image:url(' . getsliderimage1() . ',url(\'' . getsliderimage2() . ',url(\'' . getsliderimage3() . ');' . 'background-repeat: no-repeat;background-position: center; background-size: cover;min-height:100vh">'; } ?> <?php get_template_part('template-parts/header/site', 'branding'); ?> <?php get_template_part('template-parts/header/menu', 'top'); ?> </div>
slider.php code refers to
function getsliderimage1() { if (!empty(get_theme_mod('slider_image_1'))) { echo get_theme_mod('slider_image_1', get_bloginfo('template_url') . '/images/image1.jpg') . ')'; } } function getsliderimage2() { if (!empty(get_theme_mod('slider_image_2'))) { echo get_theme_mod('slider_image_2', get_bloginfo('template_url') . '/images/image1.jpg') . ')'; } } function getsliderimage3() { if (!empty(get_theme_mod('slider_image_3'))) { echo get_theme_mod('slider_image_3', get_bloginfo('template_url') . '/images/image1.jpg') . ')'; } }
my problem when turn on slider_radio not 'static' slider.php gets loaded , breaks page loaded.
obviously made mistake somewhere. can not pin point where. been searching hours now.
hoping of can tell me i'm doing wrong.
new wordpress theme development here.
thanks already!
edit :
let me explain little further. intention add image background backgrounds when used in customizer. 3 controls contain these images (or not if not used) slider_image_1 , slider_image_2 , slider_image_3
update:
it seems when paste function directly in same fille has no problems loading page anymore. hmmn
a whole lot of testing , coding later got work converting same file adjustments.
when u use echo links , use them past echo slashes deleted. u can solve using echo each part of code without functions :
like :
<header class="site-header"> <div class="row header-home" <?php if ((get_theme_mod('slider_radio', 'slider') == 'static')) { echo 'style="background-image:url(' . get_header_image() . ');' . 'background-repeat: no-repeat; background-position: center; background-size: cover;min-height:100vh">'; } else { echo 'style="background-image:'; if (!empty(get_theme_mod('slider_image_1', get_bloginfo('template_url') . '/images/image1.jpg'))) { echo 'url(' . esc_url(get_theme_mod('slider_image_1', get_bloginfo('template_url') . '/images/image1.jpg')) . ')'; if (!empty(get_theme_mod('slider_image_2', get_bloginfo('template_url') . '/images/image1.jpg')) || !empty(get_theme_mod('slider_image_3', get_bloginfo('template_url') . '/images/image1.jpg'))) { echo ','; } } if (!empty(get_theme_mod('slider_image_2', get_bloginfo('template_url') . '/images/image1.jpg'))) { echo 'url(' . esc_url(get_theme_mod('slider_image_2', get_bloginfo('template_url') . '/images/image1.jpg')) . ')'; if (!empty(get_theme_mod('slider_image_3', get_bloginfo('template_url') . '/images/image1.jpg'))) { echo ','; } } if (!empty(get_theme_mod('slider_image_3', get_bloginfo('template_url') . '/images/image1.jpg'))) { echo 'url(' . esc_url(get_theme_mod('slider_image_3', get_bloginfo('template_url') . '/images/image1.jpg')) . ')'; } echo ';'; echo 'background-repeat: no-repeat;background-position: center; background-size: cover;min-height:100vh">'; } ?> <?php get_template_part('template-parts/header/site', 'branding'); ?> <?php get_template_part('template-parts/header/menu', 'top'); ?> </div> </header>
Comments
Post a Comment