WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Children, Parents, Custom Menu (9 posts)

  1. Mr. Bigsby
    Member
    Posted 3 years ago #

    I'm using the following code. To display parents of children. I looked on the wordpress codex, but I'm not really that great with PHP and could use some help. Originally I wanted to display the PARENT and it's children no matter what child you're on. However, I made some site changes and now want to display PARENT no matter which child you're on UNLESS you're on a child that has children of its own.

    using this code:

    <?php
    global $post;
      if($post->post_parent) {
      $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      $titlenamer = get_the_title($post->post_parent);
      }
    
      else {
      $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      $titlenamer = get_the_title($post->ID);
      }
      if ($children) { ?>
    <?php } ?>
    		<h3 class="Header"><?php echo $titlenamer; ?></a></h3>
    		<ul class="Menu"><?php echo $children; ?></ul>
    	</div>

    The header is where I need the Title of the PARENT or Child (only if it has children)
    and the menu is where i need the children of the part or the child.

    Got this help on another forum, but got completely lost?

    The way to handle this would be to identify if the page had children first, then use the post id as teh "parent" in the list or find the parent if available and use that or just list all failing either.

  2. Mr. Bigsby
    Member
    Posted 3 years ago #

    To better specify -- I need a code that makes Parents display if the children don't have children.
    And Child appear in the header area if the child has it's own children.

  3. Mr. Bigsby
    Member
    Posted 3 years ago #

    This the code I have currently and it's functioning. I'd like to keep "$titlenamer" as the for the header area, despite what my edit below says. Can anyone help?

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

    This is the code I'm trying to achieve.

    <?php
    global $post;
      if($post->post_parent) {
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    $menu_title = get_the_title($post->post_parent);
    
    if($children) {
    	$menu_id = $post->ID;
    	$menu_title = $post->post_title;
    }
    
    else {
    	$menu_id = $post->post_parent;
    	$parent = get_post($menu_id);
    	$menu_title = $parent->post_title;
    }
    endif;
    ?>
  4. Mr. Bigsby
    Member
    Posted 3 years ago #

    Can no one help?

  5. Mr. Bigsby
    Member
    Posted 3 years ago #

    To Clarify ---
    I need to display PARENT and the CHILDREN of that PARENT on everypage in a setting like this

    <h2>PARENT</h2>
    <ul>CHILDREN of Parent</UL>

    unless on a page with a CHILD that has it's own children.

    in which case you would see

    <h2>CHILD</h2>
    <ul>CHILDREN of CHILD</UL>
  6. Mr. Bigsby
    Member
    Posted 3 years ago #

    forgot to mention i cant have sub children on the first type where its only children of the parent.

  7. Mr. Bigsby
    Member
    Posted 3 years ago #

    To paraphrase or re-iterate.

    I need the page to display parent and children and no subchildren unless you click on a child that has children of its own the menu would then change to the title of the child and list its children below.

  8. Mr. Bigsby
    Member
    Posted 3 years ago #

    If I'm not being clear enough, see the interior pages of http://www.webcti.com for a live example.

    There are to be 3 layers: PARENT PAGE - CHILDREN - and CHILDREN OF CHILDREN

    On nearly every page, I want to display PARENT AND CHILDREN only (no children of children). Then on pages where there are children of children I want to display the CHILD and it's children ONLY in my menu that is set up like this:

    <H2> PARENT </H2>
    <UL> CHILDREN </UL>

    for the children with children page the menu would look like this
    <H2> CHILD w/children </H2>

      Children (of above only)
  9. Ryan
    Member
    Posted 3 years ago #

    Looks like you have this working. Would you mind posting the code you used? I'd like to do something similar.

Topic Closed

This topic has been closed to new replies.

About this Topic