WordPress.org

Ready to get started?Download WordPress

Forums

Remove subpages from top menu (20 posts)

  1. nik1as
    Member
    Posted 8 years ago #

    How do I prevent subpages from being listed in the top navigation bar?
    I'm planning on having pretty many subpages, in three categories - 'Me', 'WWW', and 'Site'. And I just want those three, plus 'Home' to be in the top menu.

  2. Kafkaesqui

    Posted 8 years ago #

    If this "top navigation bar" is using wp_list_pages() to display Page links, see the Codex page on it for information on the 'depth' parameter:

    http://codex.wordpress.org/Template_Tags/wp_list_pages

    Setting 'depth' to 1 will force wp_list_pages() to display only the top (non-child) Pages.

  3. nik1as
    Member
    Posted 8 years ago #

    Hmm. I can't find it.
    This is how my header.php looks:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <?php require_once get_template_directory()."/BX_functions.php"; ?>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="<?php bloginfo('charset'); ?>" />
    <title><?php bloginfo('name'); wp_title(); ?></title>
    <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" />
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen, projection" />
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
    <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    <?php /*comments_popup_script(520, 550);*/ ?>
    <?php wp_head();?>
    </head>

    <body>
    <div id="container"<?php if (is_page() && !is_page("archives")) echo " class=\"singlecol\""; ?>>

    <!-- header ................................. -->
    <div id="header">
    <h1>"><?php bloginfo('name'); ?></h1>
    </div> <!-- /header -->

    <!-- navigation ................................. -->
    <div id="navigation">

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
    <fieldset>
    <input value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
    <input type="submit" value="Go!" id="searchbutton" name="searchbutton" />
    </fieldset>
    </form>

      <li<?php if (is_home()) echo " class='selected'"; ?>>">Home
      <?php
      $pages = BX_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";
      }
      }
      }
      ?>

    </div><!-- /navigation -->

    <hr class="low" />

  4. moshu
    Member
    Posted 8 years ago #

    It is always good to mention in your initial post the theme you are using. From the code you posted I can tell you are using the Blix, which is a nice theme but a nightmare to modify - especially for new users. Maybe the author can give you some help.

  5. Kafkaesqui

    Posted 8 years ago #

    Ah yes, the Blix theme... you'll have to do a little editing of the code above to get what you're after.

    In the PHP block above (it starts with $pages = BX_get_pages();) right after the foreach line:

    foreach ($pages as $page) {

    add this:

    if(empty($page->post_parent)) {

    Then at the end (before the closing ?> tag for the block of code), insert another closing curly bracket:

    }
    ?>

  6. nik1as
    Member
    Posted 8 years ago #

    I tried it, but it didn't work. It messed everything up - http://blog.toobigtofitinhere.com/

  7. nik1as
    Member
    Posted 8 years ago #

    If Blix is going to be this hard to configure, I might as well just use another theme.

    <b>Edit:</b> I'm now using the default theme, and I've added the depth parameter and everything works fine.
    Thanks for your help. :)

  8. Seifenspender
    Member
    Posted 8 years ago #

    Moin.

    i read the artikel with joy, because i have the same problem. But I can´t change the thema because i´ve work to long to make it perfekt for me.
    Its the site:
    http://www.driver.doppel-b.de

    The Menupoint "Impressum" should be invisible.

    Did anyone know who I could get it away?

  9. Minna
    Member
    Posted 8 years ago #

    @Seifenspender: how about adding parametre exclude=6 to the wp_list_pages template tag (I assume that's the correct page ID). That doesn't change anything too drastically, it only removes the specified page link from the list. See the Codex for info how to use the parametre. (It's just a comma-separated list of page IDs you want to exclude.)

  10. Seifenspender
    Member
    Posted 8 years ago #

    thank you . ok I want to try it.
    You mean the lines in the header.php, didn´t you?
    I not sure if I know what you mean. Where should I insert "exclude=6"?

    Here the code:
    <?php
    $pages = BX_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")

    and so on...

  11. Seifenspender
    Member
    Posted 8 years ago #

    could anybody help me?

  12. Minna
    Member
    Posted 8 years ago #

    Ahh... special functions. That's the correct place. You could add
    elseif ( $page_id==6 ) { /* ignore */ }
    after the similar looking "about_short" line (if you still have it). Before the else, anyway. Hmm, I'm not sure if the 6 should be in single quotes '6'. Try either way :)

  13. Seifenspender
    Member
    Posted 8 years ago #

    YEAH !!!
    Make me a baby.. Thanks a lot!!

    Ehm Sorry: It Works!!!!

    YEAH!!! Thank you

  14. jacobjmorris
    Member
    Posted 8 years ago #

    I love the Blix theme, however I'm having the same problem.

    I think one of our many talented WordPress CSS/PHP gurus (not me), should make an update to the Blix files so that the subpages render as a smooth and simple CSS drop down from the main navigation.

    :D

    Jacob

  15. vkaryl
    Member
    Posted 8 years ago #

    That would be something to discuss with the theme's author....

  16. jacobjmorris
    Member
    Posted 8 years ago #

    I did, I sent him an email.

  17. vkaryl
    Member
    Posted 8 years ago #

    Good job.... some of the folks here who are good with php etc. might think about it, but would depend on the time they have available of course....

  18. jacobjmorris
    Member
    Posted 8 years ago #

    I'd be willing to give someone $10 :D

  19. Brigitte
    Member
    Posted 8 years ago #

    Hm.. I'm using my own theme and I want to list pages that when selected are a different color, like in the Blix theme. I already coded all the CSS so that's fine . . . but I don't know the code so that it'll do what it's supposed to. Hm, am I making sense?

  20. mizzmuzikluvr
    Member
    Posted 7 years ago #

    Well, I've very glad that I've finally found a solution to this problem. The trouble I'm having now is that I don't understand the solution. First, I'm not quite sure where to put the edited code that Minna Suggested. In My header file I found the About_short and pasted after it, ending up with this:
    echo "<li".$selected."><a href=\"".get_page_link($page_id)."\">Contact</a></li>n";
    }
    elseif ($page_name == "about_short") {/*ignore*/}
    elseif ($page_id == '6') { /* ignore */ }
    else {
    (is_page($page_id))?$selected = ' class="selected"':$selected='';

    But I still get the funny nav bar. Not only does it still have my child pages up, but it doesn't show them imediately, only when you mouse over them and they change color. If any one could help I would appreciate it. http://vision-guild.us Thank You.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags