Support

Account

Home Forums General Issues Show one image or the other Image Reply To: Show one image or the other Image

  • Alright.. Here’s your code with a bit of cleanup/structuring. This code will randomly select either image with each page refresh and use it.

    
    <?php
    $images = array();
    if( $header_image = get_field('header_banner_image') ){
    	$images[] = $header_image;
    }
    if( $sec_header_image = get_field('secondary_header_banner_image') ){
    	$images[] = $sec_header_image;
    }
    if( !empty($images) ){
    	$use_image = array_rand($images, 1);
    	$x_pos = get_field('header_banner_position_x');
    	$y_pos = get_field('header_banner_position_y');	
    }
    ?>
    <?php if( isset( $use_image ) ): ?>
    	<div style="background-image:url(<?php echo $use_image; ?>); background-position:<?php echo $x_pos . ' ' . $y_pos; ?>;" class="page-header-ban-img" >
    <?php else: ?>
    	<div class="page-header-ban-img" >
    <?php endif; ?>