How to get the current page ID?? (4 posts)

  1. Scooby
    Posted 8 years ago #

    How the heck does one retrieve the current page ID?? I would like to use it in the body tag in my header to set an ID for current menu item since I cannot get that to work for all the blogs subpages..

  2. Scooby
    Posted 8 years ago #

    Well I don't think that will get what I'm trying to do here.. Im trying to get the main menu to highlight when going into the comments on a post.. Say I have a page named blog that shows all posts.. That page is now the current_page_item and works great.. The problem Im trying to solve is when you click to view the comments on a particular post.. The main blog link is no longer the current_page_item and I would like it to be.. Is there a possibilitly to get this to work.. I'm pretty stuck now..

  3. Scooby
    Posted 8 years ago #

    Would anybody know how to do the following?? I'm trying to get the actual page id and not the post id..

    This is what works for the post id:

    echo $post->ID;

    I'm trying to get something like this to work:

    echo $page->ID;

    Any ideas out there??

  4. Roger Theriault
    Posted 8 years ago #

    Actually I believe it is just $post->ID, if you dig into the docs you'll discover that the post table is used to store posts, pages, and attachments.

    And you can also use the template tag the_ID() instead.

    See the docs: http://codex.wordpress.org/Template_Tags

    You might also find these conditional tags helpful:

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.