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'm new to WordPress theme development and I'm trying to figure out if there is a way to display a list of public attachments similar to how you can view a list of posts with a specific tag or author.

That is, if I want to retrieve a list of posts with a specific tag, I can submit something like '?tag=mytag' in the URL and Wordpress will spit out all the posts tagged with 'mytag'. So what is the equivalent of this for viewing attachments? Or is there one?

What I'm specifically wanting to do is allow the user to click a link and have a gallery of attachments (images, video, music, etc) display. I want attachments from ALL posts on the site, not just attachments of one specific post.

I've looked into the attachment.php file, but this seems to only be to display the details of a specific attachment with a given attachment_id value (ie: '?attachment_id=246').

Can someone steer me in the right direction?

share|improve this question
add comment

1 Answer

attachment.php file displays only one attachment (like single.php or page.php).

There is no way to list all attachments without coding. WordPress doesn't have such list ready to use.

But it's rather easy to do it by yourself.

Add your custom page template. Assign it to some page. And place something like this inside this template:

$args = array(
       'post_type'=>'attachment',  // you want to show attachments
       'posts_per_page'=>-1,  // all of them
// other params
);

$attachments = new WP_Query( $args );
while ( $attachments->have_posts() ): $attachments->the_post();
//display attachment - current attachment is placed in global variable $post 
// you can also use template tags
endwhile; 
share|improve this answer
add comment

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.