基本上我正在尝试获取父页面的图库,我一直在使用query_posts来做到这一点,以下代码似乎让我更接近我需要但实际上是从其他地方获取附件而不是只有当前页面的父页面,任何一个?:
<?php
$args = array('post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => 0,
'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>';
}
?>
答案 0 :(得分:1)
您应该将post_parent设置为当前帖子父ID:
global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->post_parent,
'order_by' => 'menu_order',
'order' => 'ASC'
);