Forums

Displaying attachment image with post (1 post)

  1. disastrid
    Member
    Posted 8 months ago #

    I'm trying to display posts with an attachment image. I can display the posts, but the image attachment isn't working. Here's what I've got so far:

    <?php
    $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
    if ( ! is_array($attachments) ) continue;
    $count = count($attachments);
    $first_attachment = array_shift($attachments);
    ?>
    <?php echo wp_get_attachment_image($first_attachment->ID); ?>

    I think it's in the wp_get_attachment_image part, but not sure what I'm doing wrong. Thanks to anyone who can shed some light!

Reply

You must log in to post.

About this Topic