• abelb

    (@abelb)


    Hi,

    I am trying to create a subnavigation in the sidebar of my site.

    I have used this code below to pull the children of the parent page of the section.

    I want to also be able to pull the title of the parent page of the section and link it to its page and add to subnav.

    How would i do that? I know it has to be somewhat easy to do, just not sure the syntax.

    thanks for any help!
    a

    <?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) { ?>
      <a href=""><?php the_title(); ?></a>
      <ul id="subnav">
      <?php echo $children; ?>
      </ul>
      <?php } ?>
Viewing 1 replies (of 1 total)
  • Thread Starter abelb

    (@abelb)

    i figured it out by reading other posts. i should have done some better searching before i posted.

    this is how i created a subnav in the sidebar to be located on a Page.

    Is there a cleaner way to do it?

    <?php if($post->post_parent) {
            $parent_title = get_the_title($post->post_parent);
          	$parent_link = get_permalink($post->post_parent); ?>
          <li class="sectionName"><a href="<?php echo $parent_link; ?>"><?php echo $parent_title?></a><li>
          <?php } ?>    
    
    <?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) { ?>
    
      <?php echo $children; ?>
    
      <?php } ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Template tag to pull current page and create link to it for subnav?’ is closed to new replies.