Пытаюсь получить первое изображение из поста, но мой php-код ничего не возвращает, какая-либо помощь?
<?php while ($browndog_blog->have_posts()) : $browndog_blog->the_post();
$args = array(
'numberposts' => 1,
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_status' => null,
'post_type' => 'attachment'
);
$attachments = get_children( $args );
//print_r($attachments);
if ($attachments) {
foreach($attachments as $attachment) {
$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 '<a href="'.get_permalink($post->ID).'"><img src="'.wp_get_attachment_thumb_url( $attachment->ID ).'"></a>';
echo '<p>'.get_the_excerpt($post->ID).'</p>';
echo '<p><a href="'.get_permalink($post->ID).'">Read More</a></p>';
}
}
endwhile; ?>
Не уверен, что происходит не так, как я использую подобный код для получениявсе вложения изображений, а не только одно, и это прекрасно работает.