• Resolved Unhooked

    (@henk-burggraaff)


    I have multiple images attached to my posts/pages. Is it possible to show only one random image?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php
    $attachments = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment','post_mime_type' => 'image', 'orderby' => 'rand') );
    if($attachments) {
    $attachments = array_values($attachments);
    echo wp_get_attachment_link( $attachments[0]->ID, 'thumbnail' );
    }
    ?>

    Thread Starter Unhooked

    (@henk-burggraaff)

    Thats’s it! A simple solution without a plugin. Works perfeclty. Thanks Keesie.

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. Glad you got it resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show random attached image’ is closed to new replies.