[resolved] using the_id() (4 posts)

  1. rogueslg71
    Posted 10 years ago #

    i want to display the number of the post BEFORE the one being viewed on the screen. so if im on post 4, i would like to echo '3' in php.

    i thought that the_id() gives the post number (which it does) but since its a number, why doesnt it subtract one when i say $previousnum = the_id() -1 ; ? if i echo this, it turns out '4 - 1'. how can i get it to do the calculation, instead of treating it as a string ?

  2. That's odd. But you can do explicit casting in PHP as well.
    $previous_num = ( (int) the_id() ) - 1;

  3. Austin Matzko
    Posted 10 years ago #

    Try <?php echo($id - 1); ?>

  4. rogueslg71
    Posted 10 years ago #

    thanks filosofo that worked. otto that just gave me the same thing ( it echoed 4-1 again) but thanks anyways

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.