I followed this method of getting images from the media library.

// get the first image attached to the current post
function aldenta_get_post_image($size = 'thumbnail') {
    global $post;

    $photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );

    if ($photos) {
        $photo = array_shift($photos);
        return wp_get_attachment_image($photo->ID, $size);
    }

    return false;
}

But I want to paginate the results, how can I do that?

link|improve this question

Paginate it based on what? A set query var? A value passed into the function? – t31os Mar 9 '11 at 15:59
@t31os, currently, if there are 100 images, it will show them all, I want to limit the results to something like 20 maybe? so that the user wont see 100s of images at once – JM at Work Mar 10 '11 at 2:18
Did you post the wrong function then, the above function looks like it would only give a single result. Also, you unfortunately didn't answer my question(see previous comment). – t31os Mar 10 '11 at 11:37
feedback

2 Answers

Use the 'offset' parameter like in get_posts(). You can take the number of the page you're on as value.

link|improve this answer
feedback

get_children() returns an array of posts, not a query that can be looped through and therefore paginated.

I would encourage you to use WP_Query instead. This WPSE answer should provide a code snippet to get you started. Then it should just be a matter of looping through the query and using standard WP paging.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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