Display latest 12 images from media library

I was looking for almost a week for such solution – without success. What I want to achieve is have a kind of ‘photos cloud’ on my wordpress homepage. What I need to do is to display latest 12 photos added to media library (so not from specific posts, but in general). thumbs should appear in a square – 3 cols, 4 rows (but of course this part I can get via css). I have no brightest idea how to make it..

I’ve found such piece of code:

Read More
$args = array(
    'post_type' => 'attachment',
    'post_status' => 'published',
    'posts_per_page' =>25,
    'post_parent' => 210, // Post-> ID;
    'numberposts' => null,
);

$attachments = get_posts($args);

$post_count = count ($attachments);

if ($attachments) {
    foreach ($attachments as $attachment) {
    echo "<div class="post photo col3">";
        $url = get_attachment_link($attachment->ID);// extraigo la _posturl del attachmnet      
        $img = wp_get_attachment_url($attachment->ID);
        $title = get_the_title($attachment->post_parent);//extraigo titulo
        echo '<a href="'.$url.'"><img title="'.$title.'" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$img.'&w=350&h=500&zc=3"></a>';
        echo "</div>";
    }   
}

But I don’t know how to finalize it – without pointing to specific post. Any ideas?:) thank u!

Related posts

Leave a Reply

1 comment