WordPress.org

Ready to get started?Download WordPress

Forums

Exclude pages with get_page (2 posts)

  1. mlogos
    Member
    Posted 6 years ago #

    My client wants to be able to exclude certain pages from the navigation bar. The theme we are using has only this for navigation:

    <!-- navigation ................................. -->
    <div id="navigation">
      <ul>
        <li<?php if (is_home()) echo " class=\"selected\""; ?>><a href="<?php bloginfo('url'); ?>">Home</a></li>
        <?php
    		$pages = get_pages();
    		if ($pages) {
    			foreach ($pages as $page) {
    				$page_id = $page->ID;
       				$page_title = $page->post_title;
       				$page_name = $page->post_name;
       				if ($page_name == "archives") {
       					(is_page($page_id) || is_archive() || is_search() || is_single())?$selected = ' class="selected"':$selected='';
       					echo "<li".$selected."><a href=\"".get_page_link($page_id)."\">Archives</a></li>\n";
       				}
       				elseif($page_name == "home") {"";
       				}
    				elseif($page_name == "about") {
       					(is_page($page_id))?$selected = ' class="selected"':$selected='';
       					echo "<li".$selected."><a href=\"".get_page_link($page_id)."\">About</a></li>\n";
       				}
       				elseif ($page_name == "about_short") {/*ignore*/}
               	 	else {
                		(is_page($page_id))?$selected = ' class="selected"':$selected='';
                		echo "<li".$selected."><a href=\"".get_page_link($page_id)."\">$page_title</a></li>\n";
                	}
        		}
        	}
    		?>
      </ul>
    </div>
    <!-- /navigation -->

    How di I exclude pages without list_pages?

    Thanks...Cathy

  2. JazibUllah
    Member
    Posted 5 years ago #

    Try this

    <div id="menuholder">
        <div id="nav">
          <ul>
            <li><a href="<?php echo get_settings('home'); ?>">Home</a></li>
            <?php wp_list_pages('exclude=5'); ?>
          </ul>
        </div>

    Replace 5 with the ID of the page you want to exclude.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.