0

i try to create a simple theme. I want display several images from media library(same concept of gallery), but i don't want use POST or PAGE, just directly from media library. (of course not use wordpress gallery function too) is that possible or it's wrong way to do it?

the reason is there are several hundreds of images in library, if every image need put in a POST or a page, it's a big job. but it looks hard to manage all these images without POST or PAGE.

Thanks

1

You can use the get_posts to fetch attachments from the database. Here's some sample code to get your started. You can put it inside any template file inside your theme.

    $attachments = get_posts( array(
        'post_type' => 'attachment',
        'posts_per_page' => -1 /* get them all */
    ) );

    if ( $attachments ) {
        foreach ( $attachments as $att ) {
            $url = wp_get_attachment_url($att->ID);
            echo $url;
        }

    }

Check out the link for more parameters you can shape your query with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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