WordPress.org

Ready to get started?Download WordPress

Forums

How to display subpages only if parent is viewed? (10 posts)

  1. nobody
    Member
    Posted 9 years ago #

    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.

  2. Michael Bishop

    Posted 9 years ago #

    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.

  3. nobody
    Member
    Posted 9 years ago #

    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']) {

  4. richardlee
    Member
    Posted 9 years ago #

    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?

  5. leggo-my-eggo
    Member
    Posted 7 years ago #

    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.

  6. moshu
    Member
    Posted 7 years ago #

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

  7. reb_76
    Member
    Posted 7 years ago #

    or you could try the awesome 'Fold Page List' plugin :)

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

  8. navigadget
    Member
    Posted 7 years ago #

    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.

  9. yetsirahj
    Member
    Posted 7 years ago #

    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?

  10. SB
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic