Accessing Media/Files outside the_content

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.

Related posts

Leave a Reply

2 comments

  1. 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();
        }
    }