1

I have Website with WordPress Bootstrap:

http://www.obra-93.hr/zavrseni-projekti/

I have portfolio with items per row. The code for loop 3 items per row (totaly 20 items) is below:

    <div class="container">
<div class="row vrow">
<?php // slideshow
$args_projekti = array(
    'showposts' => -1,
    'orderby' => 'date',
    'order' => 'DESC',
    'no_found_rows' => true,
    'post_type' => 'projekti',
    'post_status' => 'publish',
    'cache_results' => false,
    'update_post_term_cache' => false,
    'update_post_meta_cache' => false
);
$projekti = new wp_query($args_projekti);
$p=0;
if ($projekti->have_posts()):
?>

    <?php
    while ($projekti->have_posts()): 
        $projekti->the_post();
            $post_id  = get_the_ID();
    ?>
        <div class="col-xs-12 col-sm-4 col-md-4">
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('projekt-thumb', array('class' => 'img-responsive fade center-block'));?></a>
            <h3 class="text-center"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
        </div>
         <?php if($p%3===0){echo '</div><div class="row vrow">';} ?>
    <?php $p++; endwhile;  endif; wp_reset_query(); ?>
    </div>
</div>

My first and last row is not working properly. Why?

Thanks!

4
  • Changed if($p%3===0) to if($p%3===1) - better, but is this soluton? Commented May 23, 2016 at 21:48
  • 1
    You probably want (($p+1) % 3 === 0) Commented May 23, 2016 at 22:33
  • 1
    Or just set your $p = 1; ;) Also there are a lot of similar answers and questions out there. For instance Commented May 24, 2016 at 6:15
  • Sure, got it working! Thank You both for ideas :) Commented May 24, 2016 at 12:14

1 Answer 1

2

if you increment $p after the if condition the values would be like
0,1,2
3,4,5
and so on an because 0 % 3 == 0 so you could start p with 1 then it looks like
1,2,3
4,5,6
or increment before the check

Sign up to request clarification or add additional context in comments.

1 Comment

Ohh, I get it now! Tried and it is working. Thanks for detailed explanation :)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.