Support » Plugins » Get id of first page in URL

  • I would like to be able to get the page id of the first element of the URL but can’t figure it out.

    I use pages and have an URL that looks like


    I would like to use the wp_list_pages function to dispaly a list of all pages in this section. In order to do this I need to know the id for the page called ‘about’.

    Does anyone know how I could get the id of about regardless of the current page?

    Any pointers would be great. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I did that on this page:

    And this is how I did it:

    Doing it outside of The Loop would be trickier, but then again, since there is only one “post” per Page, there shouldn’t really be a need to do it outside of The Loop, that is unless you’re in a different file (such as header.php).

    If that’s the case, reply and we’ll go about it a different way.

    Many thanks for the response.

    Executing the code within the loop is no problem however I what I would really like to do is be able to display a list of all the pages and sub pages within the section ‘about’ as opposed to a back button and the pages beneath it, although that is a great option.

    For example if you had a structure like


    You would get the same list regardless of which page you are on.

    To do this I think you need to know the id of the page called ‘about’. You can then feed this into the “child_of” parmaeter of wp_list_pages. If however you are a few pages down the tree I am not sure how you can get the id of “about” as it is no longer the parent of the page you are on.

    Would you have any idea how to do this? Thanks for your help, much appreciated.

    Look further down the page to the Navigation part:

    <?php wp_list_pages('child_of=' . $post->ID . '&sort_column=menu_order&depth=1&title_li='); ?>

    (Dunno why I was thinking there was more code to that and therefore had to post the whole script contents…)

    Thanks for that, I have used a modified version of your code for the “back up” link which I got from your posted code so it was worth the full post!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get id of first page in URL’ is closed to new replies.