• Resolved Mr. Bigsby

    (@holgria)


    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Mr. Bigsby

    (@holgria)

    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.

    Thread Starter Mr. Bigsby

    (@holgria)

    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;
    ?>
    Thread Starter Mr. Bigsby

    (@holgria)

    Can no one help?

    Thread Starter Mr. Bigsby

    (@holgria)

    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>

    Thread Starter Mr. Bigsby

    (@holgria)

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

    Thread Starter Mr. Bigsby

    (@holgria)

    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.

    Thread Starter Mr. Bigsby

    (@holgria)

    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)

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Children, Parents, Custom Menu’ is closed to new replies.