arrowoods
Member
Posted 2 years ago #
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>
arrowoods
Member
Posted 2 years ago #
I found the solution so if anyone 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('');
}
?>
I'm trying to do this same thing, but only want it to get the immediate parent, not the very top parent. Unfortunately I'm not a master PHP'er, but I too can cut and paste like a champ.