WordPress.org

Ready to get started?Download WordPress

Forums

get current post id? (5 posts)

  1. roobottom
    Member
    Posted 8 years ago #

    I have a single post on my homepage ( http://www.roobottom.com ) and below this I have a custom script that get 5 of the most recent posts.

    I need to know how to get the id of the post on the homepage so I can pass it to the recent post script so it'll miss out that post from the top of the list and get the next five.

    I know I could get this from the URL $p parameter, but i'm using permalinks.

    any help would be great! Thanks

  2. Ptryk
    Member
    Posted 8 years ago #

    just a guess.. but I think you should be able to use '$post_id' within the loop, passing the value of it to a variable. Then, use that variable as an exclusion within the custom get 5 recent post scripts?

  3. roobottom
    Member
    Posted 8 years ago #

    I tried echo'ing the var $post_id in the loop, but nothing happened. This would be most useful if we could access the var's for each database field for each post with a variable!

    Any other ideas? Thanks!

  4. Ptryk
    Member
    Posted 8 years ago #

    I had a few moments.. gave it a go as well.. and well, I got nothing as well... I looked at a plugin I am using that uses the same syntax $post_id and although it works there, I can't get it to work within the loop, so I am honestly left scratching my head... sorry. anyone else have any ideas?

  5. aeioux
    Member
    Posted 8 years ago #

    You can use <?php echo $post->ID ?> to output or use the current post ID.

Topic Closed

This topic has been closed to new replies.

About this Topic