WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] pages, include only!

[Resolved] pages, include only!

  • 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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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!

    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

    Kafkaesqui

    @kafkaesqui

    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));
    ?>

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] pages, include only!’ is closed to new replies.
Skip to toolbar