Skip Navigation

[Resolved] PDF thumbnail with link to PDF now that WordPress supports creating PDF image

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by James Meskunas 7 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#558202

Now that WordPress creates a images of the first page of PDF's in the media library if your server has Imagick, ImageMagick, and Ghostscript support.

Is there a way to add this to your Views? All of my PDF's now have images and thumbnails of them.

I need to have a "Coupon" CPT display the thumbnail of the PDF and that thumbnail link to the PDF.

Is this now possible?

Here is the PHP code to display a PDF thumbnail in a loop. is it possible to incorporate PHP loops into Views some how?

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();

$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);

$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '

  • ';
    echo wp_get_attachment_image( $attachment->ID, 'full' );
    echo '<p>';
    echo apply_filters( 'the_title', $attachment->post_title );
    echo '</p>
  • ';
    }
    }

    endwhile; endif; ?>

    #558234

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi James,

    Thank you for contacting our support forum.

    This lists out all the attachments for a particular post correct?

    We might be able to convert this to a shortcode to be used in our views plugin.

    Thanks,
    Shane

    #558312

    Correct.

    #558323

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi James,

    Could you try this shortcode.

    // Add Shortcode
    function pdf_list( $atts ) {
    
    	// Attributes
    	$atts = shortcode_atts(
    		array(
    			'post_id' => '',
    		),
    		$atts
    	);
    
    	$args = array(
    	'post_type' => 'attachment',
    	'numberposts' => -1,
    	'post_status' => null,
    	'post_parent' => $atts['post_id']
    	);
    	
    	$attachments = get_posts( $args );
    	$attachment_images = '';
    	if ( $attachments ) {
    	foreach ( $attachments as $attachment ) {
    	
    	$attachment_images += '<p>'.wp_get_attachment_image( $attachment->ID, 'full' ).'</p>';
    	}
    	}
    	return $attachment_images;
    
    }
    add_shortcode( 'pdf_list', 'pdf_list' );
    

    Add the above to your functions.php and you will use it in your view by doing this [pdf_list post_id='[wpv-post-id]']

    Please let me know if this works.

    Thanks,
    Shane

    #559964

    I am sure the shortcode would work under normal circumstances, but it did not resolve my issue. I think it is an issue with my site. I am testing it offline in another build.