• I know how to exclude a page from my sidebar by using the page ID:

    <?php wp_list_pages(‘title_li=<h2>Pages</h2>&exclude=ID’ ); ?>

    But is it possible to exclude multiple pages using a wildcard and the page title? e.g exlude all pages with titles starting with “Private” – such as “Private page”, “Private stuff” etc?

Viewing 1 replies (of 1 total)
  • I had a similar need, I created a page with the slug ‘home’ and created a home.php that displays it… then, to remove that page from the list of pages, I modified sidebar.php in the appropriate themes/ directory to have:


    <ul>
    <?php wp_list_pages('exclude=home&title_li='); ?>
    </ul>

    and changed function &get_pages in wp-includes/template-functions-post.php as follows:


    if ( !empty($r['exclude']) ) {
    $expages = preg_split('/[s,]+/',$r['exclude']);
    if ( count($expages) ) {
    // wl modification 20061118 -- permit exclusion by page *name* as well as ID
    // original code:
    //foreach ( $expages as $expage ) {
    // $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
    //}
    // new code:
    foreach ( $expages as $expage ) {
    if (ereg('^d+$', $expage)) {
    $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
    } else {
    $exclusions .= ' AND post_name <> "' . $expage . '" ';
    }
    }
    // end modification
    }
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude page from sidebar using wildcard title?’ is closed to new replies.