0

I am not sure if it is possible to do this but I have a category called case-studies into which I write individual posts to summarize a case-study - for the sake of this question let's give a title of cs1. This gives me a url of /case-studies/cs1. There will be more than one case study created.

I also have a PDF file containing the complete case-study (call it cs1.pdf) which I could load up into the media library or create a separate folder with a nicer URL. However in both cases the URL would not be related to the category.

What I would really like is to load up all the different case studies PDFs (either in the media library or a separate folder) and get a URL of either /case-studies/cs1.pdf or case-studies/cs1/cs1.pdf.

I do know I can't just create a folder called case-studies as this will then mess up using /case-studies to display the case-studies category page however I wondered if there might be a work around to achieve my goal?

1 Answer 1

1

If your theme has an attachment template (attachment.php) and you upload your page/post-specific media items, then you will get a page/post-specific media attachment URL.
add an image from post/page

Suppose you are adding/editing your post/page on Case Study (i.e. cs1), so your post/page URL will be (if post-name permalink structure is enabled):

http://example.com/cs1/

If you upload an image or a PDF file in this article, the image/PDF file's URL will become:

http://example.com/cs1/cs1.pdf (see 'edit' below)

So you can have a nice URL that's perfectly saying what it is and where it belongs to.

EDIT

  1. You have to have the permalink structure to post-name. You can do it from admin panel Settings » Permalinks.
  2. You can have a look how an attachment file can be from TwentyFifteen's image.php. You can use image.php for that too. I've tested using this one and it's completely working.
  3. When inserting the PDF file into the post/page remember to link it to the attachment page see edit#2 here in this linked answer. And I did say one thing wrong you will get an URL http://example.com/cs1/cs1 (there would be no extension in the URL) :)

And now it's tested. :)

2
  • I created an attachment.php using a copy of single.php (I think this is the right thing to do?) but the resulting link was a url of news/case-studies/cs1/attachment/pdf1/. This clicks through to a blank article with the heading of pdf1.
    – KTMcQuaid
    Commented Jan 26, 2015 at 17:21
  • I updated my answer Commented Jan 26, 2015 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.