0

https://www.altcinematic.co.uk/

   <?php if(have_rows('films')):
    $count = 1; ?>
    <section id="content">
        <div class="content-section">
            <?php while(have_rows('films')): the_row(); 
                if(is_int($count / 2)){
                    $position = "align-left";
                }
                else {
                    $position = "align-right";
                }
                if($video = get_sub_field('is_this_a_video') == "yes"){
                    $type = "video";
                }
                else {
                    $type = "other";
                }
                ?>
                <article class="yellow film-box <?php echo $position . " " . $type; ?>">
                    <div class="box container-box clear-fix">
                        <div class="box-right-top">
                            <div class="img video-wrap">
                                <div class="iframe-wrap">
                                    <?php the_sub_field('vimeo_link'); ?>
                                </div><!-- /iframe-wrap -->
                            </div><!-- /img -->
                        </div><!-- /box -->
                        <div class="box-left-top">
                            <h1><?php the_sub_field('title'); ?></h1>
                            <?php the_sub_field('intro_text'); ?>
                        </div>
                    </div><!-- /box -->
                </article>
            <?php $count++; endwhile; ?>
        </div><!-- /oontent-section -->
    </section><!-- /content -->
<?php endif; ?>

The above code was written to pull in some elements which are made with Advanced Custom Fields.

For the first article I am trying to get the video to float right and the text block to float left. The next article follows the pattern but in reverse. So whilst the videos float where I would like, the text blocks do not. The top article should have the text the left, whilst the second article should have the text to the right.

I've written the php this way as in theory it should be really efficient, if the blocks floated correctly.

1 Answer 1

0

Your is_int function is always returning true, because $count/2 is always an integer. is_int from the looks of it, just returns true if the parameter supplied is a number (integer), or false, if its anything else (string).

Try changing

if(is_int($count / 2)){
    ...
}

to

if($count % 2 == 0) {
    //Code for even result
}
1
  • Changing the code to if($count % 2 == 0) results in everything being displayed. However, the text blocks are still floating the wrong side. Commented Jul 30, 2017 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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