0

I want to make a modulo condition in my ACF Repeater field.

In a while loop, I want my code different if $j is odd or even.

My code:

<div class="container grow mt-5">
<h1 class="text-center">Expositions</h1>

<?php
    $j = 1;
    if( have_rows('expos') ):
        while ( have_rows('expos') ) : the_row();
        $titre= get_sub_field('titre');
        $img = get_sub_field('image');
        $contenu = get_sub_field('contenu');

        if ($j%2 == 1) {
        echo '

         <div class="row mt-5">
            <div class="col-4">
                <img class="thumbnail" src="'.echo esc_url($img['url']);.'" alt="'.esc_attr($img['alt']);.'" />    
            </div>
            <div class="col-8">
                <h2 class="text-center">'.$titre.'</h2>
                <p>'.$contenu.'</p>
            </div>
            </div>'
    } else {
        echo '
         <div class="row mt-5">
            <div class="col-8">
                <h2 class="text-center">'.$titre.'</h2>
                <p>'.$contenu.'</p>
            </div>
            <div class="col-4">
                <img class="thumbnail" src="'.echo esc_url($img['url']);.'" alt="'.esc_attr($img['alt']);.'" />    
            </div>


            </div>'
    };


    $j++;
    endwhile;
    else :
        echo '<p class="text-center">No content !</p>';
    endif;
    ?>

</div>


It doesn't work.

Where is my error ?

2
  • you are missing semicolon(;) after echo </div>' in if else block, and remove semicolon(;) from echo esc_url($img['url']); Nov 5, 2019 at 11:18
  • Thanks for answer. I remove semi-colon and find the problem: I removed echo line 17 and 32 and it works !
    – S2LF
    Nov 5, 2019 at 11:55

1 Answer 1

0

The solution was to removed echo in line 17 & 32.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.