WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] counting post not working (3 posts)

  1. canutedechou
    Member
    Posted 3 years ago #

    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?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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; ?>
  3. canutedechou
    Member
    Posted 3 years ago #

    thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.