Support » Fixing WordPress » Include the excluded pages

  • Resolved andyhoyland

    (@andyhoyland)


    Hi all…

    I was wandering (or wondering…) if it is possible to sometimes include the pages that I have excluded from my sidebar. So for example, on my index page I want to exclude pages 2,3,4 and 5 BUT if someone finds page 2 (via a different link I have set up) I would like them to be able to see links to pages 3,4 and 5 in the sidebar on page 2.

    Should I do this (and indeed, can I do this!) by setting up a sidebar for the excluded page? So page 2 has a different sidebar to my index page?!

    Did that make sense?!

    Hope so and thanks for any help.
    Regards,
    Andy.
    PS The site I am working on is http://www.stjb.org.uk – at the moment I use the very lovely Fold Page List and like the way it works but want to get rid of some pages in the sidebar!

Viewing 3 replies - 1 through 3 (of 3 total)
  • peiqinglong

    (@peiqinglong)

    PHP will do what you want. I believe the answer can be found here: http://codex.wordpress.org/Conditional_tags

    Kafkaesqui

    (@kafkaesqui)

    No extra sidebar needed (unless you really want that sort of thing). Just replace your current call to wp_list_pages() with this:

    <?php
    global $post;
    if(2 != $post->ID) {
    $exclude = '2,3,4,5';
    }
    wp_list_pages("exclude=$exclude");
    ?>

    What this does is make sure the $post object is available, then tests to see if 2 is the value for the Page ($post) ID. If it isn’t, the $exclude var is populated with the Page IDs to exclude. This var (with or without the IDs) is then provided as the value to the ‘exclude’ parameter.

    EDIT: Solution based on peiqinglong’s pointer…

    <?php
    if( is_page(2) ) {
    wp_list_pages();
    } else {
    wp_list_pages("exclude=2,3,4,5");
    }
    ?>

    andyhoyland

    (@andyhoyland)

    Great – thanks for that… it worked on my development version! Just need to try it on the full site now!

    Thank you guys.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Include the excluded pages’ is closed to new replies.