Support » Fixing WordPress » Front page post count

  • Resolved Jaxia


    Hello All –

    When I set my blog up to post 10 entries on the first page, how does it count those entries? Does it track the number somewhere?

    I’m looking for something that will look at a post and go “This is the first post on the page, assign ID of 1, this is the second post, assign ID of 2” and so on.

    Any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • skippy



    The collection of posts is assembled just before The Loop begins, based on the criteria passed on the URL.

    The easiest way to count which relative post you’re displaying through The Loop is to use a temporary counter variable, like this:

    $counter = 1;
    // Begin the Loop
    if (have_posts()) :
    while (have_posts()) : the_post();
    // just before the end of the loop, increase our counter variable
    //end the Loop


    I was hoping there was an easy answer! Thank you so much! You made my day! Can I use that exactly, or do I need to do other stuff to it?

    Thanks again,

    Skippy’s code will work fine as is.

    The main elements to pay attention to are 1. setting $counter before The Loop is initialized, and 2. incrementing ($counter++) in The Loop but at the end.

    Very cool!
    But how can I call the number? I need to output the number that it assigns to each post with the post.

    <? php counter ?>
    or something like that?




    <?php echo $counter; ?>
    will output the current value of the counter.

    Awesome! Wish me luck 😉
    I will let you know how it goes…

    That worked perfectly! Thank you so much!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Front page post count’ is closed to new replies.