• Resolved beosman

    (@beosman)


    How can I show subpages only when I select a parent page?

    I have a multipage wordpress installation and I want show subpages of a page only when the user selects the correct page.

    Thanks for your supports. Regards.


    Diego Lago

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter beosman

    (@beosman)

    I’ve solved this issue modifiying source from function-templates.php. The functions are wp_list_pages and other (I don’t remember that now).

    I will post the complete solution when I found the files (I’m not online all the time).

    Regards.


    Diego Lago

    Thread Starter beosman

    (@beosman)

    Here is the code to solve the issue:

    File: template-functions-post.php
    Function: wp_list_pages(args = ”)
    Line: 358 (aprox.)

    Add next code (into the “foreach” code block):


    $page_tree[$page->ID]['parent'] = $page->post_parent;

    ———————————–

    Into the same file:
    Function: _page_level_out(…)
    Line: 418 (aprox.)

    Add next code (into the “foreach” code block):


    $current_page = $page_tree[$GLOBALS['id']]['parent'];

    if(!($parent == 0 || ($GLOBALS['id'] == $cur_page['parent']) || ($current_parent == $cur_page['parent'])))
    continue;

    ———————

    I hope you’ll find it useful. Regards.


    Diego Lago

    This is a feature I have wanted for a while, but hacks introduce a problem with upgrading. Does anyone know of a plugin that introduces these features?

    You wouldn’t have to worry about upgrades breaking this if you defined your own functions in a seperate php file (like a plugin would). Simply copy all the function definition into your own file (myCode.php) and rename the function something like my_list_pages() and make the changes you want. Then include myCode.php once in your header or something like that.

    I’ve done this for precisely this sub-page listing functionality and it works well. If you go to my “about” page all of the “recommendeds” links on the right sidebar are actually just subpages… and that little menu is dynamically generated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show subpages when parent page is selected’ is closed to new replies.