WordPress.org

Ready to get started?Download WordPress

Forums

Exclude page from sidebar using wildcard title? (2 posts)

  1. Kerosene
    Member
    Posted 8 years ago #

    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?

  2. wlindley
    Member
    Posted 7 years ago #

    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
    }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.