• I’m desperately trying to create a really simple table-based gallery of the latest 3 uploaded images. My table is styled and all I need is to be able to call the image and place a thumbnail in each of the three table cells.

    I’ve looked at gallery plugins (none seem to style how I want) and even the Get the Image php plugin, which I can’t figure out. Can anyone help?

Viewing 1 replies (of 1 total)
  • I think this query will do what you want:

    $sql = "
    SELECT p.ID, p.guid, pm.meta_value FROM $wpdb->posts p
    JOIN $wpdb->postmeta pm ON (p.ID = pm.post_id AND pm.meta_key = '_wp_attachment_metadata')
    WHERE p.post_type = 'attachment'
    AND p.post_mime_type LIKE '%image%'
    ORDER BY p.post_date DESC
    LIMIT 0,3
    ";

    I tested this using this code:

    $img_ids = $wpdb->get_results($sql);
    foreach ($img_ids as $img) {
       $img_meta = unserialize($img->meta_value);
       $hw = $img->hwstring_small;
       echo "<p>";
       echo '<img ' . $hw . "src='$img->guid' alt='' />";
       echo '</p>';
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Get latest image with php?’ is closed to new replies.