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 に答える