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.


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

global $post;
$parent_permalink = get_permalink( $post->post_parent );
<a href="<?php echo $parent_permalink; ?>">Parent Post</a>
| improve this answer | |
  • 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"> – user1606423 May 15 '13 at 7:38
  • Modifying body_class sounds like a separate question/issue. – Chip Bennett May 15 '13 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. – Charles Clarkson May 15 '13 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. – Chip Bennett May 15 '13 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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