我试图在WordPress codex的帮助下编写一些代码片段。请检查以下内容,并根据您的需要进一步更新。我希望这有助于:
global $post;
$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 ) {
$image_attributes = wp_get_attachment_image_src( $attachment->ID, \'full\' );
echo wp_get_attachment_url($attachment->ID);
echo \'<img src="\' . wp_get_attachment_thumb_url( $attachment->ID ) . \'" class="current">\';
}
}