• Resolved shull123

    (@shull123)


    I have surfed the forums now for quite a while and need a little help solving a problem. If you get a chance, check my site at https://www.constitutionpercussion.org.

    Basically, when you add a page to the template, it is automatically added to the navigation bar in the header. So, I am trying to figure out a way to add many more pages to the site and use links to navigate to them without them being added to the navigation menu.

    Thanks for your help in advance.

Viewing 10 replies - 1 through 10 (of 10 total)
  • “many more pages”, as in, non WP Pages? You need to be more specific.
    Ah, you mean the tabs that are being created.

    Template_Tags/wp_list_pages#Exclude_Pages_from_List

    Thread Starter shull123

    (@shull123)

    Well, they will all pretty much be WP Pages if I can help it. I am simply using Word Press as a way to have multiple admins (staff members) be able to update their portions of the site. I haven’t exactly got it all set up to that point yet, but hopefully it will be finished soon.

    Right now, I am trying to add a WP Page through the Dashboard’s Page Post and keep it out of the navigation bar.

    I have tried the exclude tags, but I am not sure where to put them…and when I do include them, it adds all the pages in a list type format.

    Any thoughts?

    As the example shows
    <?php wp_list_pages('exclude=17,38&title_li=') ;?>

    would exclude pages 17 and 38

    Thread Starter shull123

    (@shull123)

    Thanks.
    But unfortunately, I tried it already and can’t exactly get it to work. I placed it in the header.php and it duplicated the entire navigation bar (all the tabs, it was pretty nasty).

    So, I know the syntax, but I can’t figure out where to put it inside template.

    Just edit the code that’s already in your header.php file, in the div navigation.

    Thread Starter shull123

    (@shull123)

    I am fairly new to WP and have spent several hours working on this issue. I know you probably hate when people paste the code, but I don’t think I have any other options. My navigation portion of the header is as follows. Any thoughts on what to change or add?

    Thanks again for your help.
    ————————

    <div id=”navigation”>

      <li<?php if (is_home()) echo ” class=\”selected\””; ?>>“>Home
      <?php
      $pages = my_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.”>Archives\n”;
      }
      elseif($page_name == “about”) {
      (is_page($page_id))?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>About\n”;
      }
      elseif ($page_name == “contact”) {
      (is_page($page_id))?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>Contact\n”;
      }
      elseif ($page_name == “about_short”) {/*ignore*/}
      else {
      (is_page($page_id))?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>$page_title\n”;
      }
      }
      }
      ?>

    First thing first, make a copy of your current header.php in case this doesn’t work.

    Next, remove all the code you just posted from the div, and paste the code I suggested.

    Then in your style sheet, change under navigation anywhere it says “selected” to “current_page_item” making sure to leave the . (period) before so
    #navigation li.selected a – becomes – #navigation li.current_page_item a

    and #navigation li.selected a:hover becomes #navigation li.current_page_item a:hover

    That should leave the CSS the same, simply you are substituting all the code the theme author concocted to create a class for the displayed page, with a built in class for the same effect.

    But I re-emphasis, make a backup in case something doesn’t work out.

    Thread Starter shull123

    (@shull123)

    Thanks a million! It worked just as you said. You have no idea how big of a help you have been. Thanks again.

    Glad I was able to help.

    When I tried to implement this solution, it did not work for me. So here is what I did.

    <?php wp_list_pages('exclude=17,38&title_li=') ;?>

    Copying and pasting this code as suggested only gets me a duplicate of my navigation menu. That sucks. But there’s a better solution. The key is finding the code for the current navigation menu and adding the exclude code to that. Much cleaner and simpler, and no double nav bar.

    Click on the presentation menu, go to theme editor and click on the header. Look for this code:

    'sort_column=menu_order&depth=1&title_li='); ?>

    This is the sort function and you can see that it is displaying the order, depth and title of each tab in the navigation. This is where we insert the exclude. For me, I wanted pages 16 and 17 excluded fromt the nav bar, so here’s what mine looks like.

    'sort_column=menu_order&exclude=16,17&depth=1&title_li='); ?>

    Notice the addition &exclude=16,17 just substitute for the page numbers you want excluded.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Navigation Bar — Exclude Menu Item’ is closed to new replies.