高级自定义字段如果为true则执行此操作

I have a tickbox for in my advanced custom fields that when ticked it puts the image above the text, I have it working but I think it can be done better than I have it. Here is what I have in my template:

 <?php if( $image_two = get_sub_field('image-two') ): ?>
    <a href="<?php echo $image_link_two; ?>">
 <img src="<?php echo $image_two; ?>" class="col-image"></a>

<?php endif; ?>

<?php if( $header_two = get_sub_field('header-two') ): ?>
  <h2 style="color: <?php echo $text_colour_two; ?>"><?php echo   $header_two; ?></h2>
<?php endif; ?>

<?php if( $subtext_two = get_sub_field('sub-text-two') ): ?>
 <span class="subtext" style="color: <?php echo $text_colour_two; ?>"><?php echo $subtext_two; ?></span>
 <?php endif; ?>

<?php if( $button_text_two = get_sub_field('button-text-two') ): ?>
 <a href="<?php echo $button_link_two; ?>"><button class="btn-text" style="color: <?php echo $button_text_colour_two; ?>; background-color: <?php echo $button_background_two; ?>"><?php echo $button_text_two ?></button></a>

<?php endif; ?>

<?php else: ?>

<?php if( $header_two = get_sub_field('header-two') ): ?>
  <h2 style="color: <?php echo $text_colour_two; ?>"><?php echo $header_two; ?></h2>
<?php endif; ?>

<?php if( $subtext_two = get_sub_field('sub-text-two') ): ?>
   <span class="subtext" style="color: <?php echo $text_colour_two; ?>"><?php echo $subtext_two; ?></span>
<?php endif; ?>

<?php if( $image_two = get_sub_field('image-two') ): ?>
  <a href="<?php echo $image_link_two; ?>"><img src="<?php echo $image_two; ?>" class="col-image"></a>
  <?php endif; ?>

  <?php if( $button_text_two = get_sub_field('button-text-two') ): ?>
     <a href="<?php echo $button_link_two; ?>"><button class="btn-text" style="color: <?php echo $button_text_colour_two; ?>; background-color: <?php echo $button_background_two; ?>"><?php echo $button_text_two ?></button></a>
  <?php endif; ?>

 <?php endif; ?>

So I'm wondering if there is a way of not having to write in the div structures twice...one with the image above the text and one with the image below the text, is there a cleaner way of doing this?

Create four functions, one for each if. Call the functions in the order you prefer. So, let's suppose you have these functions:

imageTwo, headerTwo, subtextTwo, buttonTwo

Example:

function imageTwo() {
 <?php if( $image_two = get_sub_field('image-two') ) { ?>
    <a href="<?php echo $image_link_two; ?>">
 <img src="<?php echo $image_two; ?>" class="col-image"></a>
 <php
 }
}

and then call the functions whenever you need them in the order of your preference.