• My page-tree might look like this:

    • Page 1
    • Subpage 1
    • Subpage 2
    • Page 2
    • Subpage 3
    • Subpage 4

    I want to display subpage 1 & 2 only if page 1 or subpage 1 or 2 is viewed (like shown below). Is that possible without having to hack wp? If not, could someone help me out with some code?

    • Page 1 (this is the page user is browsing)
    • Subpage 1
    • Subpage 2
    • Page 2 (user is not browsing this page, do not display subpages

    Edit:

    • Page 1
    • Subpage 1 (this is the page user is browsing)
    • Subpage 2 (user is not browsing this page, but since it is subpage 1’s ‘brother’, it is displayed)
    • Page 2 (user is not browsing this page, do not display subpages

    Hope you understand what i want.

Viewing 9 replies - 1 through 9 (of 9 total)
  • http://wordpress.org/support/topic/38298
    Take a look at this thread, and see if it is close to what you want to do. If not, let us know.

    Thread Starter nobody

    (@paitrakt)

    I think what I want to do is quite the same as in the thread you linked to, but I need a 100% dynamical solution. My dad can’t edit templates and put in extra PHP-code every time he creates a new subpage.
    I tried to edit the _page_level_out-function in WP, but it didn’t work perfectly. Subpages are now displayed if the parent is viewed, but not if one of the subpages is viewed. I replaced line 398 (i think) in template-functions-post.php with this:

    if(isset($cur_page[‘children’]) && $_GET[‘pagename’] == $cur_page[‘name’]) {

    Hey,

    Just a thought, have you tried creating your own functions with relevant queries to find out subpages?? I’m not sure exactly on the queries but sometimes you have to think out of the constraints of WP to take your site the extra mile. Have a look at the WP tables see if there are any queries you can make to create a getChildPages() function and use this within page.php (the Page template) to check for child pages for the given page

    Something like:

    if(getChildPages() > 0)
    //print the child pages

    And of course, since we all like to keep code as reusable as possible, I would stick this in a <theme_functions>.php file. Then all we need to do is include (require_once would be better) this in the top of the header.php file.

    If your still unsure of what I’m talking about, checkout the BX_functions.php in the Blix theme. See how he’s created some custom functions? Neat eh?

    I was struggling with this same issue, but it occurred to me that you could do it with these CSS rules:


    .page_item ul li {
    display: none;
    }
    .current_page_item ul li, .page_item .current_page_item {
    display: block;
    }

    Hope that helps.

    It might work for you – but being a general rule, it will prevent displaying those list items even where you want to show them.

    or you could try the awesome ‘Fold Page List’ plugin 🙂

    http://www.webspaceworks.com/resources/wordpress/30/

    I think this plug-in will do what you need:
    http://www.mealldubh.org/index.php/software/fold_page_menus/

    I use it on my site. It’s been working well.

    The fold plug-in is good but if you want to only show the subpages when you are in the parent how do you do that?

    let’s say you’re in http://www.blog.com/
    you will see:
    page 1
    page 2

    but if you are in http://www.blog.com/page 1
    you will only see:
    page 1a
    page 1b

    You will not see page 2.

    Can this be done? Is there an easy solution?

    I am also trying to figure out to only show the subpages when you are in the parent page.

    If I knew how to create plug-ins for this subject matter, I would create one now…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to display subpages only if parent is viewed?’ is closed to new replies.