Ready to get started?Download WordPress


[resolved] Trying to do simple math with the_id tag (3 posts)

  1. lukiss
    Posted 8 years ago #


    This is probably a no-brainer for someone who speaks and thinks phpsyntax. I don't however so i need your help.

    Hello want to do some simple math with the <?php the_id(); ?> tag. I would like to take the ID and subtract it from let's say 1000 so the posts are (at least displayed as) they are counting down towards 0.

    Is this is possible to do in a simple way and if so, _how_ do i do it. I only get errors with my efforts to figure it out so far.

  2. Kafkaesqui

    Posted 8 years ago #

    You can assign the ID to a variable (to use with your calculating) by using the get_the_ID() function.

    EDIT: Hmm, I thought there was a get_the_ID() function, but I just did a quick check of the source, and nope (it really should be there, though). Use this instead to call the post ID from the $post object:


  3. lukiss
    Posted 8 years ago #

    Thank You for fast answer.

    So, if anyone but me really feel the need to countdown the posts here is how to do it:

    replace <?php the_ID(); ?> with <?php echo 1000 - $post->ID ?>.

    And it works!

Topic Closed

This topic has been closed to new replies.

About this Topic