Last active
April 17, 2017 09:18
-
-
Save kirandash/c3602d94b17165abaeb3df1f912df172 to your computer and use it in GitHub Desktop.
Random banner image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Template part for displaying page content in Inner page banner | |
| * | |
| * @link https://codex.wordpress.org/Template_Hierarchy | |
| * | |
| * @package TZ_Motorsport | |
| */ | |
| $fullImgArray = array(); | |
| if(have_rows('banner_inner_pages', 'options')): while(have_rows('banner_inner_pages', 'options')): the_row(); | |
| $fullimgsrc = get_sub_field('inner_banner_image'); | |
| $smimgsrc = get_sub_field('inner_banner_image_mobile'); | |
| $fullimgurl = $fullimgsrc['url']; | |
| $smimgurl = $smimgsrc['url']; | |
| if($fullimgurl != ''): | |
| $fullImgArray[] = $fullimgurl; | |
| endif; | |
| if($smimgurl != ''): | |
| $smImgArray[] = $smimgurl; | |
| endif; | |
| endwhile;endif; | |
| $randFullImgIndex = array_rand($fullImgArray); | |
| $randFullImg = $fullImgArray[$randFullImgIndex]; | |
| $randsmImg = $smImgArray[$randFullImgIndex]; | |
| ?> | |
| <?php if($randFullImg != ''): ?> | |
| <div id="banner-inner" class="bg-cover hidden-xs" style="background-image: url(<?php echo $randFullImg; ?>);"></div> | |
| <?php endif; ?> | |
| <?php if($randsmImg != ''): ?> | |
| <div id="banner-inner" class="bg-cover visible-xs" style="background-image: url(<?php echo $randsmImg; ?>);"></div> | |
| <?php elseif($randsmImg == '' && $randFullImg != ''): ?> | |
| <div id="banner-inner" class="bg-cover visible-xs" style="background-image: url(<?php echo $randFullImg; ?>);"></div> | |
| <?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment