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 am trying to display the attachments of a custom post type based on their file name (numbering at the end) and then assign it to a title.

I have 10 pre-defined titles that I want to link to a specific attachment if it's available (meaning the file is currently attached to the post), and if it can't find the file, the title won't display.

So I have a ul of links with the same titles for each post of the CPT:

Title 1 --> FileName-01.jpg or pdf
Title 2 --> FileName-02.jpg or pdf
Title 3 --> FileName-02.jpg or pdf
etc.

HTML would be something like:

<ul>
 <li><a href="Link-to-FileName-01">Pre-defined Title 1</a></li>
 <li><a href="Link-to-FileName-02">Pre-defined Title 2</a></li>
</ul>

If it can't find the specific file in the attachments, the title won't be displayed. So if attachment 2 is missing, Title 2 wont be displayed.

Title 1 --> FileName-01.jpg or pdf
Title 3 --> FileName-02.jpg or pdf

I can do this to find the attachments minus featured image: List Post Attachments - Remove Image Thumbnails

Not sure how I would filter and match the attachments though.

Thanks!

More info:

Basically they have a library with 200+ data pages on different scientific methods/research. The data pages include different sections with research info, tables, formulas, etc (which I have set up a template for using the advanced custom fields plugin), and list with links to up to the 10 jpg/pdf files (charts, diagrams,etc). The hyperlink titles for those are always the same, just the filenames change.

So, I am trying to achieve the above so that I can (and later the client) just copy the text, tables, etc into the appropriate sections of the template, and then upload all the attachments (jpg,pdf) at once (once meaning all files for each post). Then the function would list the 10 or less hyperlinks to the attached jpg,pdf files. This way I, and later the client, don't have to create the hyperlinks manually for each file.

Currently I can list all attachments, but I'm not exactly sure how I would set up the array so that it automatically checks how many files have been uploaded, matches the last 2 digits of the file name to the correct title, omits the titles that don't have a matching file, and finally outputs the generated links to attached files within the post.

share|improve this question
1  
Can you explain why you need to do this? It is easier to help when I know the point. –  s_ha_dum Sep 7 '13 at 23:12
    
To save time, otherwise would have to do it manually for each file. And since we're adding hundreds of posts with up to 10 files and the link titles for the files never change (just the files themselves - they're scientific charts/data-plots), achieving this would be much easier/faster. –  Nuro Sep 7 '13 at 23:58
    
Ok. One time import then? I still can't quite tell exactly what you've done so far or what you have to work with. –  s_ha_dum Sep 8 '13 at 0:56
    
200 or so for now, but they may want to add more down the line. I've added more information to my initial question. Thanks! –  Nuro Sep 8 '13 at 3:13
    
You want to do this through the media uploader? –  s_ha_dum Sep 8 '13 at 15:12
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.