0

Is it posible to get the parent ID of an single page.... I mean not a Page I mean an is_single()... page.

I have a page witch contains some custom posts and when I click on one of these i came to the single page of these entree. I would like to get the permalink of the parent page, the page i come from.

0

1 Answer 1

0

For a hierarchical post type, you can use $post->post_parent and get_permalink(), perhaps like so:

<?php
global $post;
$parent_permalink = get_permalink( $post->post_parent );
?>
<a href="<?php echo $parent_permalink; ?>">Parent Post</a>
4
  • thats clear, but im on a single.php page i get no parent in the body class etc. <body class="single single-news postid-1098 single-format-standard"> Commented May 15, 2013 at 7:38
  • Modifying body_class sounds like a separate question/issue. Commented May 15, 2013 at 11:46
  • Parent information classes are added to the body class in get_body_class() under the test for is_page(). The code under the is_single() test does not add those classes. If you want them on your CPT single.php page body class, you will have to add them yourself. Commented May 15, 2013 at 17:56
  • If this answer does not adequately answer your underlying question, please edit your question, to clarify more precisely what you're trying to accomplish. Then, I can edit the answer accordingly. Commented May 15, 2013 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.