Forums

[resolved] Show all images from a post in correct order? (4 posts)

  1. jonas18z
    Member
    Posted 1 year ago #

    I want to view all images on a page, I have used this function under but i don't sort the images if i enter numbers or use the sort function in gallery and i want to use the "medium" size not the full. Is it possible in some way in wordpress?

    <?php
     $args = array(
        'post_type' => 'attachment',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => $post->ID
        );
    
    $attachments = get_posts($args);
    if ($attachments) {
        foreach ($attachments as $attachment) {
            if(wp_attachment_is_image( $attachment->ID )) {
            echo '<img src="'. wp_get_attachment_url($attachment->ID) . '" alt="gallery" width="600" height="400" />';
            break;
        }
    }
    }
     ?>
  2. Mark / t31os
    Moderator
    Posted 1 year ago #

    Try adding the following to your args array..

    'orderby' => 'menu_order',

    Might also want to change the order direction..

    'order' => 'asc',

    or

    'order' => 'desc',

    ..whichever is appropriate..

  3. jonas18z
    Member
    Posted 1 year ago #

    thank you!

  4. Mark / t31os
    Moderator
    Posted 1 year ago #

    You're welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic