WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] pages, include only! (5 posts)

  1. mkyb14
    Member
    Posted 7 years ago #

    I see many posts here about excluding pages etc... I'm wanting to know if there is a way to only INCLUDE certian pages, so that i'm not always having to update the exclude list.

    Making it so that only the pages I need as a sidebar have the few pages I want!

  2. scormeny
    Member
    Posted 7 years ago #

    If it were my I'd go the poor man's route and just "hard-code" the html for the pages I wanted included, rather than using any fancy wordpress php code.

    Maybe that's so obvious you overlooked it, so I just wanted to chime in.

    Best of luck!

  3. mkyb14
    Member
    Posted 7 years ago #

    true, just wanted to know if there was such a function of wordpress so that eventually IF I became motivated that i might actually write a plugin for the installed theme for the sidebar... something simplier that could be installed for everyone

  4. Kafkaesqui

    Posted 7 years ago #

    scormeny's solution: +1. But if you really want to, this will do what you want (just don't tell anyone I told you!):

    <?php
    $include = '10,11,12'; // Page IDs to 'include'
    $status = 'post_status = \'static\'';
    $exclude = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $status AND ID NOT IN ($include)");
    wp_list_pages('exclude=' . implode(',', $exclude));
    ?>

    Note for the future:
    The reason for the extra $status line above is because with the next major version update to WordPress (probably 2.1), you want to change it to this:

    $status = 'post_type = \'page\'';

    Or, just do this and you're covered:

    <?php
    $include = '10,11,12'; // Page IDs to 'include'
    $status = ($wp_version < 2.1) ? 'post_status = \'static\'' : 'post_type = \'page\'';
    $exclude = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $status AND ID NOT IN ($include)");
    wp_list_pages('exclude=' . implode(',', $exclude));
    ?>
  5. ergate
    Member
    Posted 7 years ago #

    The 2.1 version of Kafkaesquis code works with the 2.1 release.
    I have a question about it though, is it possible to have that code display the included the subpages of that page? Other than just adding the pages physically.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags