Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

$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!

share|improve this question

1 Answer 1

Simply omit the parent value.

$args = array(
    'post_type' => 'attachment',
    'post_status' => 'published',
    'numberposts' => 12,
);

Check the documentation for other arguments: Function_Reference/get_posts.

Maybe you'd like to use the PHP command shuffle, like shuffle( $attachments );.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.