WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Exclude all sub-pages from main header (7 posts)

  1. josalmon
    Member
    Posted 8 years ago #

    Hi everyone,

    I want to develop an entire site using WP rather than just a blog but I'm having problems with sub-pages.

    On my main page, I've got the list of Pages but as I now have to create sub-pages, I don't want them displayed on the main page - only on the parent Page relating to them

    For example, if I created two Pages, one about dogs and one about cats and then created a sub-page about dog food, I would only want the dog food Page to show up on the dogs Page.

    I can do the sub-Page list on individual pages no problems, but I'm having problemds excluding the sub pages from the main menu

    I'm currently using this code:

    <?php wp_list_pages('exclude=10&title_li='); ?>

    but I'm looking at creating 40 or so sub-pages scattered between 10 or so Pages.

    Is there a way of saying "exclude all sub pages" without having to go back to the original Page list and insert the sub-page ID each and every time I create one?

    To summarise - does anyone know some code that will only display Parent Pages?

    Cheers, Jo

  2. josalmon
    Member
    Posted 8 years ago #

    It's fine, I figured it out!

    For anyone else who is interested, use this code to display the Parent Pages only:

    <?php wp_list_pages('depth=1&title_li='); ?>

  3. TechGnome
    Moderator
    Posted 8 years ago #

    Which can be found here: Codex Entry for wp_list_pages

    Tg

  4. josalmon
    Member
    Posted 8 years ago #

    I find the codex really hard to read - I went through it for an hour before I posted and nearly an hour after. But that's why I posted again so you wouldn't have to respond.

  5. TechGnome
    Moderator
    Posted 8 years ago #

    The post was more for others comming along afterwards who may find it useful.

    Tg
    PS: I find the Codex quite convoluted myself.

  6. nay-k
    Member
    Posted 8 years ago #

    I tried to do this but it doesn't work for me.
    this is the code in my sidebar.php:

    <!-- <?php wp_list_pages('depth=1&title_li=<h2>' . __('Pages') . '</h2>' ); ?> -->

    did I do something wrong???

  7. nay-k
    Member
    Posted 8 years ago #

    I changed it to:
    <!-- <?php wp_list_pages('depth=1' . __('Pages') . '</h2>' ); ?> -->
    but it still doesn't work. I read the codex about that but I can't find whats wrong!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.