Parent Permalinks
-
Im currently using code to call the parent page title as a link above my sidebar menu on content pages, as well as a ‘back to parent’ button at the bottom.
Code for Parent Page Title Link in functions.php:
function my_page_ancestor() { global $post; if( !is_front_page() ) { $parents = get_post_ancestors( $post ); $top_parent_link = get_permalink( end($parents) ); echo '<a href="' . $top_parent_link . '"><span class="pageAncestor">' . get_the_title( end($parents) ) . '</span></a>'; } }Code used in template:
<?php my_page_ancestor();?>Code used to display back to parent link on page (code placed in template file):
<?php if($post->post_parent) { $parent_link = get_permalink($post->post_parent); ?> <a href="<?php echo $parent_link; ?>">← Go back a step</a>My problem is, when I click to a child of a child of the parent post, both links disappear. Eg, when clicked on ‘Parent’ and ‘Child 1’ bellow everything works fine. When I click on ‘Child 2’, the links are gone.
IE
Parent
– child 1
– – child 2
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Parent Permalinks’ is closed to new replies.