• I am playing around with the wp_list_pages-tag, and I am not able to figure out if it is possible to make it “fold” when clicking pages which has sub pages.

    What I am trying to do is this: When looking at the “top” page, the list of pages should look like

    * About us
    * Products
    * Contact us

    But actually “Products” has several sub pages, and when the visitor clicks the “Products” link making it the current page I want the list to “fold out” revealing the links to the sub pages. Like this:

    * About us
    * Products
    — * Apples
    — * Bananas
    — * Oranges
    * Contact us

    If the sub pages can fold in and out in a similar way it would be lurvely. Is that at all possible?

Viewing 15 replies - 1 through 15 (of 17 total)
  • A quick and dirty PHP if/else *test* which should work:

    <?php if(is_page('Products') || is_page('Apples') || is_page('Bananas') || is_page('Oranges')) : ?>
    <?php wp_list_pages(); ?>
    <?php else : ?>
    <?php wp_list_pages('exclude=1, 2, 3'); ?>
    <?php endif; ?>

    ‘1, 2, 3’ in the exclude parameter would equal the numeric Page IDs for Apples, Bananas and Oranges.

    If by “sub pages can fold in and out” you mean you’re looking to hide the Page link when on that particular Page:

    <?php if(is_page('Products')) : ?>
    <?php wp_list_pages(); ?>
    <?php elseif(is_page('Apples')) : ?>
    <?php wp_list_pages('exclude=1'); ?>
    <?php elseif(is_page('Bananas')) : ?>
    <?php wp_list_pages('exclude=2'); ?>
    <?php elseif(is_page('Oranges')) : ?>
    <?php wp_list_pages('exclude=3'); ?>
    <?php else : ?>
    <?php wp_list_pages('exclude=1, 2, 3'); ?>
    <?php endif; ?>

    Thread Starter manne

    (@manne)

    Excellent clues, thank you. I will fiddle around and see if I cana ccomplish what I want to do, which is more like the navigation on the left side of this site (see how the menu folds in and out revealing sub pages in several levels as you click them):

    https://www.renhallningsbolaget.halmstad.se/

    I’m looking for precisely the same thing and that php hack is indeed dirty… In my case I’ve got about 30 pages, constantly increasing.

    What’s more puzzling is that the depth parameter is not working properly (or, rather, logically):
    <?php wp_list_pages('depth=1'); ?>

    One should think that if the current URL is domain.com/, then displayed pages will be only level-ones. Then, as we advance to, say, domain.com/help/, logic tells us we’ll se all the level-one links, relative to the current depth. Alas, that’s not the case…

    child_of: Display only the subpages of the Page…

    Another note – maybe the child_of parameter could be used if modified in such way, so it would display all pages, below the currently selected by default. So we don’t have to set specific page ID…

    Yet another thought – if there was a way to sneak the_ID into something like this – that do fine ?? :
    <?php wp_list_pages('child_of=the_ID()'); ?>

    I’m too new to WordPress and not quite sure if there’s a way to pass a variable (either from the $post array or else) as a parameter to the wp_list_pages function…

    Hello all,

    I have been running into the same limitations with wp_list_pages(), I’m particularly interested in BobyDimitrov’s idea, that would be fine indeed!

    For now I’ll just settle for the bugs being fixed so the function actually works correctly, let’s hope for 1.5.1…

    Thread Starter manne

    (@manne)

    Yeah, the way I have solved my “problem” now (not really a problem, actually more like trying to do what WordPress not yet is capable of) is to use hard coded includes for each main section of the site listing the sub pages for that section. So if I want to add a sub page in a section I first add it in the WordPress “Page tree” and then manually add its’ link in the correct include file.

    For anyone wanting to get the folding of page lists working, I have posted a plugin that does just that, by extending the functionality provided by wp_list_pages in a new template tag, wswwpx_fold_page_list.

    In principal this could be used as a replacement for wp_list_pages since in essence it is simply a modified version of that tag. It should (this is not fully tested) support all the functionality of wp_list_pages, and its accepted arguments are identical to that template tag.

    One slight modification of behaviour, when specifying a non-zero ‘child_of’, this function will return all descendants, not just those of the first generation… the visibility of subsequent generations is handled by the ‘level’ argument.

    I have currently only placed this on my website, but will move it to the plugins repository shortly.

    A page explaining installation and use, and a link to a downloadable zip archive is available at https://www.webspaceworks.com/wp-plugins/foldpagelist.html.

    I’d welcome any feedback…

    roblgs solution solved it for me. I had accomplished almost the same thing with a lot of coding in my sidebar template, but this is better. Thanks!

    Thank you, roblgs! Just what I needed! Otherwise I would have been forced to choose between showing just two levels, and miss pages, and showing all three, with an unreadable list.

    WordPress has a built-in dropdown_cats function

    Unfortunately, the coders have not yet included a similar dropdown_pages function

    (I requested the feature and thought it would be included in 1.5.1 – but it was not)

    Roblgs, your plugin is exactly what I am after. However, it breaks the plugin I use for translating my website into Japanese (polyglot). Do you know of a fix to this?

    roblgs

    (@roblgs)

    Hi Tomkun,

    I’m not familiar with polyglot at all. How exactly does it break? Can you provide further information… better still through direct email to the address in the header to the plugin, to guarantee that I see it as quickly as possible…

    Cheers

    Rob

    roblgs

    (@roblgs)

    Hi,

    I have posted a new update to the Fold Category List plugin that resolves various issues of non-functionality under WP1.5.2.

    The new version is, as ever, available from the Fold Category List support page.

    Best regards

    Rob

    Thanks for a great plugin.

    What would I need to edit to expand ALL the children, grand-children, etc of the current page? Right now it only expands one level below (with depth=0)

    Hi Josepo,

    I’m happy to announce that a new version of the Fold Page List plugin does exactly what you ask.

    Enjoy!

    Rob

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘How make menu (wp_list_pages) “fold”’ is closed to new replies.