WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] using the_id() (4 posts)

  1. rogueslg71
    Member
    Posted 8 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. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

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

  3. Austin Matzko
    Member
    Posted 8 years ago #

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

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

Tags

No tags yet.