auto-increment counter (6 posts)

  1. julianens
    Posted 7 years ago #

    where can I find an auto-increment counter for wordpress?
    I want it to returns a number that is incremented each time this tag is called.
    so that I can count the front-page posts.. identifying them as
    <div id='post1'>
    <div id='post2'>
    <div id='post3'>
    <div id='post4'>
    and so on.. automaticaly..

    how can i do that?

    thanks in advance.

  2. stvwlf
    Posted 7 years ago #

    it's built in

    $wp_query->post_count is the # of posts on the page

    $wp_query->current_post is the # of the current post on the page

    current post starts at zero, post_count starts at 1

  3. Shane G
    Posted 7 years ago #


    I personally refer you to go with the statcounter plugin for statistics for your site..you can download it from here:



    Shane G.

  4. julianens
    Posted 7 years ago #


    i undestand that the <?php the_ID(); ?> tag does the counting automatically.
    but its count is very strange.. cause it goes from 49 on the first post to 43 on the second post.

    what i really need is a simple increasing id number.. starting from 0.
    exactly like this:
    <div id='post0'> for post one (most recent post)
    <div id='post1'> for post two
    <div id='post9'> for post ten (last post of the page)

    i know that textpattern has a plugin called rvm_counter that does this like a charm. but I wanted something for wordpress.

    how can I add this on the loop? is that possible on wordpress?

    thanks in advance.

  5. julianens
    Posted 7 years ago #

    oh, i got it now.

    i wrote <div id="post<?php echo($wp_query->current_post + 1); ?>"> to the loop and it worked.

    thanks! :)

  6. ciuchlux
    Posted 7 years ago #

    Is it posible to show count from last one ?
    post 11
    post 10

Topic Closed

This topic has been closed to new replies.

About this Topic