Title: Linking to parent&#8230; HELP!!
Last modified: August 19, 2016

---

# Linking to parent… HELP!!

 *  [arrowoods](https://wordpress.org/support/users/arrowoods/)
 * (@arrowoods)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/linking-to-parent-help/)
 * I am using the below code in my nav. It works perfectly at showing me the top
   level parent of the page no matter what subpage I am on. The only issue I am 
   having is making it a link back to that page. Can someone tell me what to do 
   to make it link back… I am a php newbie but I am a master cut and paster. Thanks
 *     ```
       <div id="sideNavParent">
       	<?php
       if($post->post_parent) {
       $ancestors = get_post_ancestors($post->ID);
       $root = count($ancestors)-1;
       $parent = $ancestors[$root];
       $parent_title = get_the_title($parent);
       echo $parent_title;
       } else {
       wp_title('');
       }
       ?>
       </div>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [arrowoods](https://wordpress.org/support/users/arrowoods/)
 * (@arrowoods)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/linking-to-parent-help/#post-1357530)
 * you can view an example here. [http://www.franklinchristianchurch.com/groups](http://www.franklinchristianchurch.com/groups)
   I want groups to be clickable and link to the groups page so when you are on 
   child pages you can get back to it.
 *  Thread Starter [arrowoods](https://wordpress.org/support/users/arrowoods/)
 * (@arrowoods)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/linking-to-parent-help/#post-1357556)
 * Well I found my own solution, and anyone else who needs it here it is.
 *     ```
       <?php
       if($post->post_parent) {
       $ancestors = get_post_ancestors($post->ID);
       $root = count($ancestors)-1;
       $parent = $ancestors[$root];
       $parent_title = get_the_title($parent);?>
       <a href="<?php echo get_permalink($parent) ?>"><?php echo $parent_title;?></a>
       <?php
       } else {
       wp_title('');
       }
       ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Linking to parent… HELP!!’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [arrowoods](https://wordpress.org/support/users/arrowoods/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/linking-to-parent-help/#post-1357556)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
