0

In my wordpress site, I have multiple PDFs that I need to display in individual pages. I could just create a page for each PDF, but this seems very tedious. The pages will each be very similar, they will just have a different PDF embedded. I would like to do be able to create a template which creates a separate page for each PDF in the DB. Each page would have a URL that looks something like /pdf/:id.

Ideally I would like to do this with a plugin, because only the system administrator has access to the source code.

Thank you for your help.

  • how are generated the PDF ? – mmm Apr 13 '18 at 11:48
  • The PDFs are already generated. They're like newsletters. I have an archive of 100 or so PDF newsletters. I'd like to have a page per PDF. – Sam Phillips Apr 13 '18 at 11:57
0

If you really want to include them in a page, you could create a page template which pulls in the requested PDF by ID. So for example, you create the Page www.example.com/pdf/ and add a query string so when someone visits www.example.com/pdf/?id=234 they see the PDF which has a post ID of 234. Within the Page Template, you'd check

// make sure id is present in the url
if(!empty($_GET['id'])) {
wp_get_attachment_url( $id );
    // get the url to the pdf
    $pdf = wp_get_attachment_url( $_GET['id'] );
    // now add your desired code to embed/link/display the pdf
}

Depending on your needs, perhaps you don't really need a Page wrapped around the PDFs. You could instead just link directly to the PDFs since most modern browsers will navigate to them and display them in a more flexible, responsive way than embedding them within a Page. With this approach, if you need a link to every PDF, you could create a Page Template that instead searches for all media where the file type is PDF, then have a foreach loop that links to the specific URL. You'd just want to make sure that each PDF within the Media Library has a decently readable Title so the text of the link makes sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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