skip to Main Content

I know very little php and virtually no bootstrap but I’m trying to update a wordpress template to adjust where an image appears on a page. The website uses the Advanced Custom Fields plugin to be able to use the same framework throughout the website. The php is using those fields and adding loops and if statements to change the which side of the page the image is on. This is the webpage of the template I’m adjusting.

I’m trying to make it so the image in the blue "Services" section appears on the left instead of the right. This is the php for that portion:

 <?php get_template_part('waves/blue', 'top-one'); ?>
        <div id="about-wrapper" class="wrapper">
        
           <div class="wrapper">
            <div class="<?php echo esc_attr( $container ); ?> back-forth-text-image">
                <?php $sections = get_field('lirtb_sections'); ?>
                <?php $numOfRows = count($sections) - 1; ?>

                <?php foreach($sections as $skey=>$section){ ?>
                    <div class="row <?php echo($skey < $numOfRows ? 'margin-bottom-double sm-margin-bottom-half' : '') ?>">
                        <div class="col-12 col-md-6 <?php echo ($skey % 2 != 0 ? 'pl-5' : '')?>  bft-text padding-right-half">
                            <div class="bft-text-container">
                                <h6 class="sans-serif font-weight-bold emphasis no-margin"><?php echo $section['lirtb_title'] ?></h6>
                                <h3 class="h2"><?php echo $section['lirtb_header']?></h3>
                                <div class="first-p margin-bottom-half">
                                    <?php echo $section['lirtb_text']?>
                                </div>
                                <?php if(
                                        isset($section['lirtb_button_text']) &&
                                         !empty($section['lirtb_button_text']) &&
                                         isset($section['lirtb_link']) &&
                                         !empty($section['lirtb_link'])){?>
                                <a href="<?php echo $section['lirtb_link'] ?>" type="button" class="btn transparent"><?php echo $section['lirtb_button_text'] ?></a>
                                <?php } ?>
                            </div>
                        </div>

                        <div class="col-12 col-md-6  bft-image sm-margin-bottom-quarter">
                        <div class="row">
                            <img src="<?php echo $section['lirtb_image']['url']?>" />
                        </div>  
                        <div class="row">
                            <img src="<?php echo $section['lirtb2_image']['url']?>" />
                        </div>
                        </div>
                    </div>
                <?php } ?>
            </div>
        </div>
        </div>
        <?php get_template_part('waves/blue', 'bottom-one'); ?>

I dont’ need the loop since it’s only one section in the with the blue background so I tried to take the loop out and things just went side ways from there…. Thanks in advance!

2

Answers


  1. It’s better to use CSS to do this sort of change, but simply by changing the place of div that hold images, you can show them at first, like the code below. Also, don’t remove "foreach", it’s handle data from database.

     <?php get_template_part('waves/blue', 'top-one'); ?>
            <div id="about-wrapper" class="wrapper">
            
               <div class="wrapper">
                <div class="<?php echo esc_attr( $container ); ?> back-forth-text-image">
                    <?php $sections = get_field('lirtb_sections'); ?>
                    <?php $numOfRows = count($sections) - 1; ?>
    
                    <?php foreach($sections as $skey=>$section){ ?>
                        <div class="row <?php echo($skey < $numOfRows ? 'margin-bottom-double sm-margin-bottom-half' : '') ?>">
                            <div class="col-12 col-md-6  bft-image sm-margin-bottom-quarter">
                            <div class="row">
                                <img src="<?php echo $section['lirtb_image']['url']?>" />
                            </div>  
                            <div class="row">
                                <img src="<?php echo $section['lirtb2_image']['url']?>" />
                            </div>
                            </div>
                            <div class="col-12 col-md-6 <?php echo ($skey % 2 != 0 ? 'pl-5' : '')?>  bft-text padding-right-half">
                                <div class="bft-text-container">
                                    <h6 class="sans-serif font-weight-bold emphasis no-margin"><?php echo $section['lirtb_title'] ?></h6>
                                    <h3 class="h2"><?php echo $section['lirtb_header']?></h3>
                                    <div class="first-p margin-bottom-half">
                                        <?php echo $section['lirtb_text']?>
                                    </div>
                                    <?php if(
                                            isset($section['lirtb_button_text']) &&
                                             !empty($section['lirtb_button_text']) &&
                                             isset($section['lirtb_link']) &&
                                             !empty($section['lirtb_link'])){?>
                                    <a href="<?php echo $section['lirtb_link'] ?>" type="button" class="btn transparent"><?php echo $section['lirtb_button_text'] ?></a>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    <?php } ?>
                </div>
            </div>
            </div>
            <?php get_template_part('waves/blue', 'bottom-one'); ?>
    
    Login or Signup to reply.
  2. Just by adding .order-first class to the second column div that contains your image, will display column first in the parent row.

    Not sure if you can implement this safely via your ACF builder.

    See working example below…

    #about-wrapper {
      background: #c5dbf2;
      min-height: 400px;
      width: 100%;
    }
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
    
    <div class="wave-wrapper"><svg version="1.1" id="" class="sfg-wave top" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1440 100" style="enable-background:new 0 0 1440 100" xml:space="preserve"><style type="text/css">.st2{fill:#c5dbf2}.wave-2,.wave-3,.wave-4{visibility:hidden}</style><path transform="scale(-1, -1) translate(-1440, -100)" id="" class="st2 wave-1" fill="#c5dbf2" fill-rule="evenodd" d="M0 0h1440c-296.556 8-565.33 24.052-806.323 48.155C392.685 72.258 181.46 56.206 0 0z"></path></svg></div>
    
    <div id="about-wrapper" class="wrapper">
      <div class="wrapper py-4">
        <div class="container-md container-fluid back-forth-text-image">
          <div class="row align-items-center">
            <div class="col-12 col-sm-6 bft-text padding-right-half">
              <div class="bft-text-container">
                <h6 class="sans-serif font-weight-bold emphasis no-margin"></h6>
                <h3 class="h2">Lorem Ipsum</h3>
                <div class="first-p margin-bottom-half">
                  <p>Sed nec justo a velit ultrices laoreet eget nec justo:</p>
                  <ul>
                    <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;"><a href="#">Vivamus eu ligula eget nisi accumsan bibendum</a>,  elit eget volutpat dignissim, dolor mi eleifend justo.</span></li>
                    <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;"><a href="#">Nulla facilisi</a> vel fringilla nulla sem eu justo volutpat.</span></li>
                    <li style="font-weight: 400;" aria-level="1"><a href="#"><span style="font-weight: 400;">In et hendrerit sapien</span></a></li>
                  </ul>
                  <p><span style="font-weight: 400;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, lorem eu ultricies vehicula, urna nulla consequat justo, in varius libero lacus ut arcu. Nunc vitae elit et odio dignissim facilisis.</span></p>
                </div>
              </div>
            </div>
            <div class="col-12 col-sm-6 bft-image sm-margin-bottom-quarter order-first">
              <div class="row">
                <img src="https://i.imgur.com/nRB5xz4.png" class="img-fluid entered lazyloaded"><noscript><img src="https://i.imgur.com/nRB5xz4.png" /></noscript>
              </div>
              <div class="row">
                <img src="">
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="wave-wrapper"><svg version="1.1" id="" class="sfg-wave bottom" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1440 100" style="enable-background:new 0 0 1440 100; margin-bottom: 20px;" xml:space="preserve"><style type="text/css">.st3{fill:#c5dbf2}.wave-2,.wave-3,.wave-4{visibility:hidden}</style><path id="" class="st3 wave-1" fill="#c5dbf2" fill-rule="evenodd" d="M0 0h1440v31.065c-461.292-14.26-805.86.525-1033.703 44.355C178.454 119.249 43.021 104.464 0 31.065V0z"></path></svg></div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search