我尝试了这个,它实际显示的是当前页面内容而不是父内容:
<?php
$my_postid = 3105;
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
echo $content;
?>
还尝试了以下但我收到了警告:
Warning: Missing argument 1 for get_page(), called in:
代码:
<?php
$page = get_page();
$parentID = $page['post_parent'];
if($parentID != '0') {
$parentPage = get_page($parentID);
$parentContent = $parentPage['post_content'];
$parentContent = apply_filters('the_content', $parentContent);
echo $parentContent;
}
?>
答案 0 :(得分:2)
global $post;
if ($post->post_parent) {
$parent = get_page($post->post_parent);
echo apply_filters('the_content', $parent->post_content);
}
答案 1 :(得分:1)
鉴于一些加载的帖子:
$id = 3105;
$content_post = get_post($id);
您可以获取其父级:
$parent_id = $content_post->post_parent; // Will be 0 if the post has no parent
$parent = get_post($parent_id);
输出内容:
echo $parent->post_content;
答案 2 :(得分:0)
这最终有效,关键是使用全球$ post;
<?php
global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->post_parent,
'order_by' => 'menu_order',
'order' => 'ASC'
);
$attachments = get_posts($args);
if($attachments)
{
echo '<ul class="imagelist">';
foreach($attachments as $attachment)
{
echo '<li>';
$large = wp_get_attachment_image_src($attachment->ID, 'large');
$thumb = wp_get_attachment_image($attachment->ID, 'thumbnail');
echo '<a href="'. $large[0] .'">' . $thumb . '</a>';
echo '</li>';
}
echo '</ul>';
}
?>