WordPress.org

Ready to get started?Download WordPress

Forums

How to get the post id BEFORE the_post() is invoked? (2 posts)

  1. Aw Guo
    Member
    Posted 5 years ago #

    I am using wordpress 2.2+

    I want to get the post id with PHP technical. However, when trying to get that via get_the_ID or $id, it works fine in sidebar.php and footer.php but NOT working in header.php

    I think that's due to a invoking of "the_post". I tested and found that if I put the the_post() in header.php it could really get the id. However, if I do so, something will be wrong and the post will be not shown.

    So is there anyway to get the id before invoking "the_post" in a header.php file?

    Thanks!

  2. jonkemp
    Member
    Posted 5 years ago #

    You need to use a function like this.

    if(is_page($ID)) {
    	some code here;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic