开发者

wordpress templating get the content of parent page

开发者 https://www.devze.com 2023-03-03 22:03 出处:网络
how do i get the_content for the parent page when templating in WP? (pages-only structure) preferably wo plugins o开发者_JAVA技巧r sql.

how do i get the_content for the parent page when templating in WP?

(pages-only structure)

preferably wo plugins o开发者_JAVA技巧r sql.

regards, /t


<?php $page = get_page(); // gets current page ID
      $parentID = $page['post_parent']; // gets parent ID, if there is one
      if($parentID != '0') {
        $parentPage = get_page($parentID);
        $parentContent = $parentPage['post_content']; // gets raw content
        $parentContent = apply_filters('the_content', $parentContent); // filters content
      } ?>

That's one way to do it.


$parent = get_post($post->post_parent);

then you can do

$parentContent = $parent->post_content

FYI, get_page() wraps get_post()

0

精彩评论

暂无评论...
验证码 换一张
取 消