Title: Code Example
Last modified: August 22, 2016

---

# Code Example

 *  Resolved [JordanC26](https://wordpress.org/support/users/jordanc26/)
 * (@jordanc26)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/code-example/)
 * Hi,
 * Would you be able to provide a code snippet to display the image and link for
   the uploaded PDF’s, having a hard time figuring it out.
 * I am also using ACF if still possible?
 * Also, whilst I know the thumbnail in the media gallery only appears after refresh,
   do I need to select the thumbnail when the page refreshes also?
 * Upload PDF
    Save/Refresh Select Thumbnail this time instead Update Post?
 * [https://wordpress.org/plugins/pdf-thumbnails/](https://wordpress.org/plugins/pdf-thumbnails/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [stianlik](https://wordpress.org/support/users/stianlik/)
 * (@stianlik)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/code-example/#post-5552203)
 * Hi,
 * You can create a download link for the PDF with the following snippet:
 *     ```
       <?php $id = get_the_ID(); ?>
       <a href="<?php echo wp_get_attachment_url($id); ?>">
           <?php echo get_the_post_thumbnail($id); ?>
       </a>
       ```
   
 * Replace `$id` with ID of the PDF attachment you are interested in linking to.
   The example assumes that you are in “The Loop”, viewing an attachment page.
 * The plugin should not cause any problems from ACF as far as i know. Thumbnails
   are saved as normal uploads in the media library.
 * The thumbnail is automatically attached to the PDF as a “featured image” when
   PDF is uploaded. No need to perform additional steps here.
 *  Thread Starter [JordanC26](https://wordpress.org/support/users/jordanc26/)
 * (@jordanc26)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/code-example/#post-5552212)
 * I’m using the following on the page which should show the PDF thumbnail.
    [http://bit.ly/1vwydDl](http://bit.ly/1vwydDl)
 * I can’t figure how to get the attachment ID for the attachment on this page. 
   I manually put the ID for a moment and works.
    Also, will this work if I have
   multiple PDF’s on the same page (which I intend to).
 *     ```
       if( have_rows('pdf_files') ): ?>
   
           <ul>
   
           <?php while( have_rows('pdf_files') ): the_row(); ?>
   
               <li><?php the_sub_field('case_study_pdf'); ?></li>
   
               <?php $id = 31510; ?>
               <a href="<?php echo wp_get_attachment_url($id); ?>">
                   <?php echo get_the_post_thumbnail($id); ?>
               </a>
   
           <?php endwhile; ?>
   
           </ul>
   
       <?php
   
           elseif( !empty($old_pdf1) ):
           the_field('old_pdf_file_1');
       ?>
   
       <?php endif; ?>
       ```
   
 *  Plugin Author [stianlik](https://wordpress.org/support/users/stianlik/)
 * (@stianlik)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/code-example/#post-5552225)
 * Yes, this will work if you have multiple PDF’s on the same page. PDF thumbnails
   are implemented as [Post_Thumbnails](http://codex.wordpress.org/Post_Thumbnails)
   for attachments and can be used in the same way.
 * I have never used ACF, so I’m not familiar with the API you’re using. However,
   I found some documentation for the [ACF File](http://www.advancedcustomfields.com/resources/file/)
   field. To get the attachment ID, you need to set `Return Value` to `Attachment
   ID` instead of `File URL`. The preceding link has an example of how you can proceed,
   in short, use `$attachment_id = get_field('case_study_pdf');` to get the `$id`
   after setting `Return Value` to `Attachment ID` in the field configuration screen.
 *  [jonnixon](https://wordpress.org/support/users/jonnixon/)
 * (@jonnixon)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/code-example/#post-5552292)
 * Hi guys – I have the exact same setup using ACF. However, I can’t get anything
   at all to render. I double-checked that both GS and Imagick are installed, etc.
   Any thoughts? I even tried manually setting the ID. Still no dice. Thoughts?
 *  [jonnixon](https://wordpress.org/support/users/jonnixon/)
 * (@jonnixon)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/code-example/#post-5552293)
 * Update: I figured it out. I deleted my PDFs and re-uploaded (since I installed
   the plugin after I uploaded my original PDFs) and the thumbnails were created.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Code Example’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/pdf-thumbnails.svg)
 * [PDF Thumbnails](https://wordpress.org/plugins/pdf-thumbnails/)
 * [Support Threads](https://wordpress.org/support/plugin/pdf-thumbnails/)
 * [Active Topics](https://wordpress.org/support/plugin/pdf-thumbnails/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pdf-thumbnails/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [jonnixon](https://wordpress.org/support/users/jonnixon/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/code-example/#post-5552293)
 * Status: resolved