WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to show child pages? (3 posts)

  1. ssamik
    Member
    Posted 6 years ago #

    I've used this guide: http://codex.wordpress.org/Creating_Horizontal_Menus to create my menus and I'm quite happy with the result. However, I would like the children of any given page to show under that menu, so that my users can navigate simply between my pages. Now, how could i accomplish that?

  2. ssamik
    Member
    Posted 6 years ago #

    Solved... Found this page: http://codex.wordpress.org/Template_Tags/wp_list_pages

    Used this one:

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    to list subpages even if on a subpage, and it works like a charm.

  3. dennymathews
    Member
    Posted 5 years ago #

    I'm using a free theme called "Simplicity". I used the above code to display the child menu items but it doesn't work. I'm pasting the code from the files "header.php" and from "style.css". I hope you could shed some light on this because I'm stumped.

    Excerpt from "header.php" file:
    <div id="headermenu">

      <?php
      if($post->post_parent)
      $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      $string = wp_list_pages('title_li=&echo=0&depth=1' );
      $pattern = ' current_page_item "';$replacement = '" id="current"';
      echo str_replace($pattern, $replacement, $string); ?>
      if ($children) { echo $children; }

    </div><!-- headermenu -->

    Excerpt from "style.css" file:
    /* headermenu */
    #headermenu {
    padding: 0 1em;
    width: auto;
    background: transparent;
    font-family: 'Lucida Grande', Verdana, Helvetica, Sans-Serif;
    }
    #headermenu ul {
    font-size: 11px;
    font-weight: bold;
    margin: 0;
    padding: 0;
    list-style: none;
    border: 0;
    }
    #headermenu li {
    display: inline;
    margin: 0;
    padding: 0;
    text-transform: uppercase;
    }
    #headermenu li:first-child { margin-left: 10px; }
    #headermenu a {
    float: left;
    line-height: 1em;
    display: block;
    background-color: #58a;
    color: white;
    margin: 0 10px 0 0;
    padding: 0.5em 10px;
    }
    #headermenu a:hover {
    background-color: #7ac;
    text-decoration: none;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic