0

I add flexslider to my theme home page via this code.how can I get number of per item?

as 1 2 3 4 ......

    <?php
        $args = array( 'post_type' => 'try', 'posts_per_page' => 3 );
        $query = new WP_Query( $args );
        while ($query->have_posts()) : $query->the_post();

    ?>

      <li class="featured-game">
        <?php the_post_thumbnail('featured'); ?>
        <div class="caption">
            <a href="#" class="game-title"><?php the_title();?></a>
            <?php the_excerpt(); ?>
            <a href="#" class="playnow">Play Now</a>
        </div>
      </li>

    <?php
        endwhile;
    ?>
</ul>

2

You can use

$item_nr = $query->current_post;

to give you the position within the loop (starts from 0).

If you need the first item to start with 1, you can use:

$item_nr = $query->current_post;
$item_nr++;

Total number of posts found:

$items_found = $query->found_posts;
  • thanks. I found css value as text-indent: -9999px; for hiding. – ahmetlutfu Apr 1 '13 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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