Support » Themes and Templates » Trying to do simple math with the_id tag

  • Resolved lukiss

    (@lukiss)


    Hello!

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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:

    $post->ID

    Thread Starter lukiss

    (@lukiss)

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to do simple math with the_id tag’ is closed to new replies.