0

I want to show as

 <div class="team-list-wrapper clearfix wow fadeInUp"  data-wow-duration="1s" data-wow-delay="0.5s">
<ul id="co-team">
<li class="nav team-list">
<li>
<li class="nav team-list">
<li>
<li class="nav team-list">
<li>
<li class="nav team-list">
<li>
</ul>
<ul id="co-team">
<li class="nav team-list">
<li>
<li class="nav team-list">
<li>
<li class="nav team-list">
<li>
<li class="nav team-list">
<li>
</ul>
</div>

And below is the code I am using:

<div class="team-list-wrapper clearfix wow fadeInUp"  data-wow-duration="1s" data-wow-delay="0.5s">
<?php $args=array( 'post_type'=>'our-team', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo ''; $i = 0; while ($my_query->have_posts()) : $my_query->the_post(); if($i % 4 == 0) { ?>
<ul id="co-team">
    <?php } ?>
    <li class="nav team-list">
        <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id());?>" title="<?php echo get_the_title();?>" alt="<?php echo get_the_title();?>">
        <div class="hover-item">
            <div class="actv-desc">
                <div class="team-details">
                    <div class="name">
                        <?php echo get_the_title();?><span><?php the_field('designation'); ?></span>
                    </div>
                    <?php get_template_part( 'post', 'content'); ?>
                </div>
            </div>
        </div>
    </li>
    <?php if($i % 4==0 ) { ?>
</ul>
<?php } $i++; endwhile; } wp_reset_query(); ?>
</div>

And my output is:

<ul id="co-team">
<li class="nav team-list">
</ul>
<li class="nav team-list">
<li class="nav team-list">
<li class="nav team-list">
<ul id="co-team">
<li class="nav team-list">
</ul>
<li class="nav team-list">
<li class="nav team-list">
<li class="nav team-list">
<ul id="co-team">
<li class="nav team-list">
</ul>
<li class="nav team-list">
<li class="nav team-list">
<li class="nav team-list">
<ul id="co-team">
<li class="nav team-list">
</ul> 

Please help.

1

You need to make two changes in your code

  1. Use $i = 1 instead of $i = 0 (before begining of while loop)
  2. You have 2 IF condition in which you using % symbol. You need to make changes in first if condition (only in opening ul tag).

Just replace

if($i % 4 == 0) {

with this

 if($i % 4 == 1) {

NOTE: Don't make this change in your second IF condition (codition with closing UL tag i.e. ).

To check what's the difference between previous output and this one, just print value of variable i ($i) near title of post and your will notice why this changes required and how it actually solved the problem.

| improve this answer | |

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