WordPress.org

Ready to get started?Download WordPress

Forums

auto-increment counter (6 posts)

  1. julianens
    Member
    Posted 4 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
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    Hi,

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

    http://wordpress.org/extend/plugins/official-statcounter-plugin-for-wordpress/

    Thanks,

    Shane G.

  4. julianens
    Member
    Posted 4 years ago #

    stvwlf,

    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
    ...
    until..
    <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
    Member
    Posted 4 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
    Member
    Posted 4 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