Support » Fixing WordPress » Only show first attachment of post

  • Hello,
    What’s the best way to show only the first image (or attachment) of a post? I’m using this for the code and the problem I’m having is that the last image is shown as the first image. What I want to do is show the first image as the first. I’ve tried changing menu_order to ASC and DESC and that doesn’t work as well.

    <?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, 'Front'); ?>

    I’m open to all suggestions as to how to solve this problem.

    Thanks and have a great year,
    Gregory S.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Only show first attachment of post’ is closed to new replies.