[Resolved] Trying suggestions for PDF thumbnails, not working
This support ticket is created 3 years, 6 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.
Tell us what you are trying to do?
I'm trying to implement the accepted suggestion for displaying PDF thumbnails in a view loop.
I expect to see a grid of medium-sized PDF thumbnail images linking to the corresponding single page.
Instead, I get a grid of links with the raw text of the shortcode as the link [getpublicationpdfimg size=”medium”]
I did add the code to my child theme's functions.php (I use GeneratePress) and replaced the publication_document string with the slug of the file field, as indicated, which is called journalpdf.
This got me closer, thanks for helping me. For some reason, the img code is getting messed up in between the a tag and it's breaking the image. It's adding an errant </a> tag right after the image url, and before the quote. Why would it be doing this?
To be clear, some quotes are changing to the HTML code for a quotation mark, looking at the source code when I inspect in Chrome. In particular, the quotes around the class="pubdoc-pdf-image" in the Template code.
As far as I can see the code is working correctly, however there is something that is converting the URL that is being returned into a link already, at this point i'm not sure what is causing this but it is not coming from the custom code itself.
I would recommend turning off all your non-toolset plugins as well as checking any other custom code on your site to see what could be causing this.
Given that this is custom code there is not much that I can do with this.
Thank you for trying, I appreciate it. I will disable some plugins and see if I can find the culprit here. I will post back if and when I find it in case others have this issue.
I ended up finding a script that automatically sets the featured image with the thumbnail attachment of the PDF when the post is saved. The 'journal-issues' portion would need be changed to your custom post type slug, this goes in your theme's functions.php. Then I just used the standard button for the featured image url to call the images for the loop. It's funny that WordPress generates these thumbnails automatically now, and yet makes it so hard to actually use them in any kind of automated way.
function save_pdf_thumb_as_featuredimage ( $post_id ) {
if ( wp_is_post_revision( $post_id ) ) return;
if ( get_post_type( $post_id ) !== 'journal-issues' ) return; // set your post type
if ( get_post_meta( $post_id, '_thumbnail_id', true ) ) return; // post already has featured image
$attaches = get_posts ( 'post_parent='.$post_id.'&numberposts=-1&post_type=attachment&post_mime_type=application/pdf&orderby=menu_order&order=ASC' );
if ( $attaches ): foreach( $attaches as $attach ):
if ( $thumb_id = get_post_meta( $attach->ID, '_thumbnail_id', true ) ){ // if pdf has thumbnail
update_post_meta( $post_id, '_thumbnail_id', $thumb_id );
break;
}
endforeach; endif;
}
add_action( 'save_post', 'save_pdf_thumb_as_featuredimage' );
Thanks for your help!
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.