Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:55:42+00:00 2026-06-04T07:55:42+00:00

Looking for any pointers really. The functionality I’m after Basically I’d like to have

  • 0

Looking for any pointers really.

The functionality I’m after

Basically I’d like to have the functionality to assign up to 6 different images to one single post. All 6 images will be displayed as normal within single.php. On the homepage, for example, I’d then like one of those images to be randomly displayed on page load for that post.

A couple of questions

  1. Is this even possible?
  2. Is there a plugin that can manage this sort of thing?
  3. If I were to do it myself how should I go about creating this sort of functionality?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:55:43+00:00Added an answer on June 4, 2026 at 7:55 am

    Yes it is possible, and not all that difficult. You upload the images when creating the post.

    Then in single.php you use get_children to get all images from the post.

    assuming in the loop:

    $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=$post->ID' );
    

    and output them like so:

    if ($images)
    {
    foreach ( $images as $attachment_id => $attachment ) {
            echo wp_get_attachment_image( $attachment_id, 'full' );
        }
    }
    

    For your random image you could either use the same get_children as above but add &numberposts=1 to the args string.

    or something like:

     function fetch_random_img($postid='') {
        global $wpdb;
        if (empty($postid))
        {
           //we are going for random post and random image
         $postid = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY RAND() LIMIT 1");
        }
        $imageid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wp_posts WHERE post_type='attachment' AND post_mime_type LIKE 'image/%' AND post_parent=$postid ORDER BY RAND() LIMIT 1"));
        if ($imageid) {
             echo wp_get_attachment_image( $imageid, 'full' );
        }
        else {
        return false;
        }
    
        }
    

    This will give you only one random image, and it will be random, whereas get_children will pull out the same image each time unless you add order and orderby arguments, which will allow you to change which image comes out.

    To echo the image within a div just call the function:

    <div>
    <?php fetch_random_img(); ?>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for any pointers on how to write a rails web app without
I'm having a really strange problem and I'm looking for any possible ideas. I
I'm looking for an example of a 'device ring', somewhat like the one used
I have a couple of elements, one of which may have any number of
I am really a newbie to Moodle and I have got this advanced functionality
I'm pretty new to iPhone programming, so I'm looking for any pointers (no pun
I have started looking into the Rabbyt library and so far I am really
im looking for any information about a builtin algorithm in opengl es to convert
I'm looking for any beyond basic resources that can help me to be proficient
I am looking for any tips or resources on importing from excel into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.