用同样的方法尝试get_children
. 它会帮你的。下面是一个示例代码。
$args = array(
\'numberposts\' => -1,
\'order\' => \'ASC\',
\'post_mime_type\' => \'image\',
\'post_parent\' => $post->ID,
\'post_status\' => null,
\'post_type\' => \'attachment\',
);
$attachments = get_children( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo $attachment->post_title;
echo $attachment->post_content;
$image_attributes = wp_get_attachment_image_src( $attachment->ID, \'thumbnail\' ) ? wp_get_attachment_image_src( $attachment->ID, \'thumbnail\' ) : wp_get_attachment_image_src( $attachment->ID, \'full\' );
echo \'<img src="\' . wp_get_attachment_thumb_url( $attachment->ID ) . \'" class="current">\';
}
}
我不确定你代码中的问题。但这会给你带来结果。