Support » Plugins and Hacks » Hacks » counting post not working

  • Resolved canutedechou

    (@canutedechou)


    when i use post with thumbnails, usually, the last of the line has a special css property to be applyed for get a good design

    i usually use

    <div class="work-post <?php if ($count%4 == 0) { echo 'last'; $count2=0; } ?>"> (thanks to alchymyth for these one)

    so, each 4 post, i can apply a special css rule to get a clear design.
    but, now im using another type of array for post, and that rule is not working anymore
    i have

    <?php
    $args = array( 'posts_per_page' => 20, 'category__not_in' => array(5,6,7,8,9) );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    	<div class="spot <?php if ($count == 4 || $count == 8) { echo 'last'; $count2=0; } ?>"></div>
    <?php endforeach; ?>

    but, now i really dont know why, the “last” property is not being applyed
    any idea?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    but, now i really dont know why, the “last” property is not being applyed
    any idea?

    at least in your shown code section, the counter is not incremented;

    try:

    <?php
    $args = array( 'posts_per_page' => 20, 'category__not_in' => array(5,6,7,8,9) );
    $lastposts = get_posts( $args );
    $count = 0; //initialize counter
    foreach($lastposts as $post) : setup_postdata($post); ?>
    	<div class="spot <?php if ($count%4 == 0) { echo 'last'; }; $count++; ?>"></div>
    <?php endforeach; ?>

    thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘counting post not working’ is closed to new replies.