Grow your CSS skills. Land your dream job.

WP help: exclude a specific page’s children from nav

  • # May 25, 2011 at 5:40 pm

    My nav is currently generated by:



      < ?php wp_list_pages("title_li=&depth=2"); ?>

    This lists all the top-level pages and all direct children of those pages.
    One of my top-level pages has around 18 direct children, and I’m wondering if there’s a way to tell the exclude parameter to simply exclude all children of this one top-level page, rather than hard code a list all 18 pages for the exclude.
    I tried something like:


      < ?php $exclude = 'child_of=49';?>
      < ?php wp_list_pages("exclude=$exclude&title_li=&depth=2"); ?>

    49 being the page # of the top-level parent w/the 18 children. But this removed the top-level page from the nav.

    # May 26, 2011 at 12:53 am

    Hi

    It can be easily done and your not far off all you need to do is get the page id’s as the id of the page in the database not the div id. You can find the idea of page by clicking on pages and hovering over those pages and the id will be at the end of the url. You then use the exclude bit and place in comma separated id’s. The other ways are using exclude tree which gets rid of parent and hiding them with css but you should really use the first way.

    Here is the function reference which shows you how to do this:
    Your text to link…

    Hope this helps!

    # May 26, 2011 at 2:07 am

    49 is the page id, I think my using of # in the context I did to mean number as opposed to id was misleading.
    Saying ‘exclude=49′ is not what I want though, 49 has a bunch of children pages, and I want to exclude those while keeping 49, and my thinking is I can exclude them by creating a variable that targets all of them, as opposed to doing ‘exclude=14,67,45,34,etc..’ in the event that additional children pages are created later this would prevent having to go back in and add those pages to the php.

    # May 26, 2011 at 5:00 am

    You may try these plugins
    http://wordpress.org/extend/plugins/exclude-pages/
    http://wordpress.org/extend/plugins/simply-exclude/
    yet I’m not sure they will work for you.

    # May 26, 2011 at 7:40 am

    you can just exclude the children pages all you have to do is get their id not the parent and yes you can save them into a variable if you wish!

    # May 26, 2011 at 1:24 pm

    As an easier way of identifying id numbers for post, pages, etc, try the Reveal IDs plugin — it shows the id numbers (post, pages, categories, you name it) in the Dashboard interface. Invaluable for building loops easily.

    # May 26, 2011 at 3:41 pm

    Could you instead list only the top level pages and then when on that page, you could include the menu for subpages?

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".