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 building a site and each post has a PDF file attachment. Is there a way I can access that file outside the_content() on a single post page? I'd like to put the file attachment in a sidebar and not in the body of the post.

share|improve this question
add comment

2 Answers

Try the following code:

$args = array(
'post_type' => 'attachment', 
'numberposts' => -1, 
'post_status' => null, 
'post_parent' => $post->ID 
); 
$attachments = get_posts( $args );
if ($attachments) {
    foreach ( $attachments as $attachment) {
        setup_postdata($attachment);
        the_title();
        the_attachment_link($attachment->ID, false);
        the_excerpt();
    }
}
share|improve this answer
    
Thanks Maxim - When I do that I get a lot of extra text that doesn't seem to be related to the attachment. I took out the_title() and the_excerpt() but need to figure out formatting. –  matthewvb Jun 19 '12 at 18:04
    
Also would like to figure out how to exclude an attachment from this list -- or better yet set an attachment as "featured" and only display that. –  matthewvb Jun 19 '12 at 18:05
    
I ended up using the WP-Filebase Download plugin. This allowed me to pull the attachments into a shortcode list that I could put in my template file outside the_content(). –  matthewvb Jun 19 '12 at 18:29
    
I think I don't understand what you expect to receive. Do you you need a shortcode? or better formatting? or both? –  Maxim Orlovsky Jun 21 '12 at 8:05
    
I was searching for a plugin that would allow me to set a "featured attachment" and then use a shortcode or some php on the page to allow for that attachment to be downloaded. Sorry I wasn't clear. –  matthewvb Jun 21 '12 at 12:45
add comment
up vote 0 down vote accepted

I ended up using the WP-Filebase Download plugin. This allowed me to pull the attachments into a shortcode list that I could put in my template file outside `

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.