Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter seanjacob

    (@seanjacob)

    <!-- the loop-->
    <?php if (have_posts()) : ?>
    
    <!-- new variable for post count -->
    <?php $c = 0; ?>
    
    <!-- begin THE LOOP -->
    <?php while (have_posts()) : the_post(); ?>
    
    <!--open div class-->
    <?php if ($c == 0 || $c == 10 || $c == 20 || $c == 30 ) { ?> <div class="slider"> <?php  } ?> 
    
    <!-- increments post count with each post -->
    <?php $c++; ?>
    
    <!-- post content -->
    <div class="post"><?php the_content(); ?></div>
    
    <!--close div class-->
    <?php if ($c == 10 || $c == 20 || $c == 30 ) { ?> </div> <?php  } ?>  
    
    <!-- end of the loop-->
    <?php endwhile; else:?>

    Obvious problem doesn’t go to infinity,

    And a bigger problem is that the div will not close if not a 10th post, so if the post is like 24 will not be able to close the div. But I am sure ill find a work around and update.

    Thread Starter seanjacob

    (@seanjacob)

    <!-- the loop-->
    <?php if (have_posts()) : ?>
    
    <!-- new variable for post count -->
    <?php $c = 0; ?>
    
    <!-- begin THE LOOP -->
    <?php while (have_posts()) : the_post();?>
    
    <!--open div class-->
    <?php if( $c == 0) { ?><div class="slider"><?php } ?>
    
    <!-- increments post count with each post -->
    <?php $c++; ?>
    
    <!-- post content -->
    <div class="post"><?php the_content(); ?></div>
    
    <!--close div class-->
    <?php if( $c == 10) {?></div><?php $c = 0;} ?>
    
    <!-- end of the loop-->
    <?php endwhile; else:?><?php endif; ?>
    
    <!-- if not ended on a 10th post close div -->
    <?php if( $c == 10 || $c == 0) {} else {?></div><?php } ?>

    Please let me know if this worked for anyone or if you are having trouble.

    DigitalSquid

    (@twelvefootsnowman)

    Actually, that code I posted was wrong. Don’t use it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘LOOP: Put a class around every 10 posts.’ is closed to new replies.