1

基本上我正在尝试获取父页面的画廊,并且我一直在使用 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>';
}
?>
4

1 回答 1

2

您应该已将 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'
);
于 2012-06-28T18:09:07.410 回答