Forums

[resolved] Get Post Attachment URLs from the Loop (2 posts)

  1. JTWilcox
    Member
    Posted 1 year ago #

    Hello,

    I am trying to pull an attachment URL for my posts from the loop.

    More specifically, I am in archive pages, using archives to display each of my categories. Some of my posts will contain links to download PDFs. Back in the archive/category loop, I am pulling the excerpt for each post, but I'm not sure how to get the link to the PDF from within each post and display that below the excerpt.

    I found this post:

    http://wordpress.org/support/topic/referring-to-an-attachment-file-in-the-loop?replies=3

    Which is along the lines of what I need, but it seems to be pulling just the most recent attachment from the media library and including a link to that on every post, rather than pulling the PDF links from within each individual post.

    Any ideas? Thanks.

  2. JTWilcox
    Member
    Posted 11 months ago #

    I ended up working through this and getting to something that works for me. Here's what I'm using:

    http://pastebin.com/are59P17

    This could pose a problem, however, because all it's really doing is pulling the most recent attachment from the post. So if the attachment is not a PDF, it doesn't know. And if there is a PDF and then someone attaches an image, it will grab the image.

Topic Closed

This topic has been closed to new replies.

About this Topic