WordPress.org

Ready to get started?Download WordPress

Forums

Get id of first page in URL (5 posts)

  1. Keir Whitaker
    Member
    Posted 8 years ago #

    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

    /about/company/people

    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.

  2. I did that on this page: http://www.viper007bond.com/about/

    And this is how I did it: http://www.viper007bond.com/wordpress/wp-content/themes/neat_1024/page-listchildren.phps

    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.

  3. Keir Whitaker
    Member
    Posted 8 years ago #

    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

    /about
    /about/company/
    /about/company/people

    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.

  4. 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...)

  5. Keir Whitaker
    Member
    Posted 8 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags