stianlik
Forum Replies Created
-
Forum: Plugins
In reply to: [PDF Thumbnails] Thumbnail is created, but not added to PDF fileHi,
First, a control question: Did you upload both images after you activated the plugin? If the answer is no, you can regenerate the thumbnails, or simply delete the PDF and upload it a second time with the plugin activated.
Can you check if the thumbnail image has been generated? It will be saved as a normal image and you can find it in the media manager with title “Winter_2014_Newsletter_V1-thumbnail”.
PDF thumbnails are connected to the PDF in the same way as featured images are to posts, with the meta key
_thumbnail_id
on the PDF attachment. Additionally every PDF thumbnail is marked with post metaPdfThumbnailsPlugin
set totrue
.I uploaded both of the files you linked to on a test installation and was able to retrieve thumbnails for both.
Forum: Plugins
In reply to: [PDF Thumbnails] Cannot ActivateThis may be caused by an outdated server setup. The
__DIR__
constant is not supported for PHP versions older than 5.3. Can you check which version you are running?I just releasted a new version that should be backward compatible with PHP 5.2. Please update to version 0.0.5 and let me know if it works. Thanks.
Forum: Plugins
In reply to: [PDF Thumbnails] Code ExampleYes, this will work if you have multiple PDF’s on the same page. PDF thumbnails are implemented as 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 field. To get the attachment ID, you need to set
Return Value
toAttachment ID
instead ofFile 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 settingReturn Value
toAttachment ID
in the field configuration screen.Forum: Plugins
In reply to: [PDF Thumbnails] Code ExampleHi,
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.
Forum: Plugins
In reply to: [PDF Thumbnails] Nothing but error messagesIf you are up to it, you will probably get a more helpful error message in the web server log. You can find the log file in the following places:
- Debian/Ubuntu:
/var/log/apache2/error.log
- OSX:
/var/log/apache2/error_log
Othewise, it may be helpful to enable debug-mode for WordPress by editing
wp-config.php
, see Editing wp-config.php for details.Forum: Plugins
In reply to: [PDF Thumbnails] Nothing but error messagesCan you post the error message you are getting?
If you have PDF support in imagick, this plugin should be working. The reason that you need Ghostscript, is to enable PDF support for imagick.
Forum: Plugins
In reply to: [PDF Thumbnails] How to implement in themeGreat! Thank you for posting the solution, and a great review.
Actually,
get_the_post_thumbnail($id)
callswp_get_attachment_image_src($id)
internally, so you should be able to make it work with the code below. In my earlier comment,$filethumb
should have been$attachment_id
, sorry for the blunder.<?php $attachment_id = get_field('file'); ?> <div class="thumb"> <?php echo get_the_post_thumbnail($attachment_id, 'medium'); ?> </div>
That would make your code slightly easier to read.
Forum: Plugins
In reply to: [PDF Thumbnails] Regenerate ThumbnailsGood look with your imports, marking this as resolved ??
Forum: Plugins
In reply to: [PDF Thumbnails] How to implement in themeA subtle detail of
the_post_thumbnail()
is that it only works with current post in The Loop, you cannot pass an ID to that function. Your code should work if you replacethe_post_thumbnail
withecho get_the_post_thumbnail
:<?php echo get_the_post_thumbnail($filethumb); ?>
Forum: Plugins
In reply to: [PDF Thumbnails] Regenerate ThumbnailsYou are correct, thumbnails is generated by hooking into the
wp_generate_attachment_metadata
hook, which triggers when you upload a new file.Unfortunately, the regenerate thumbnails plugin only loops through images, so it will not trigger thumbnail generation for PDFs. It would be useful to support the regenerate thumbnails plugin. I will check with the author to see if we can figure something out. However, I reckon that will take some time.
For now, you can do it manually with the following code snippet:
add_action('admin_init', function () { if (!isset($_GET['regenerate_pdf_thumbnails'])) { return; } $chunk_size = empty($_GET['regenerate_pdf_thumbnails_chunk_size']) ? -1 : $_GET['regenerate_pdf_thumbnails_chunk_size']; // Get all attachments $posts = get_posts(array( 'post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => $chunk_size, 'fields' => 'ids', 'paged' => (int) $_GET['regenerate_pdf_thumbnails'], 'meta_key' => 'PdfThumbnailsPlugin', 'meta_compare' => 'NOT EXISTS' )); // Regenerate metadata (incl. thumbnails and pdf thumnails) foreach ($posts as $id) { $file = get_attached_file($id); $meta = wp_generate_attachment_metadata($id, $file); update_post_meta($id, $meta); } });
With that you can use
https://YOURSITE?regenerate_pdf_thumbnails
to trigger the generation. To avoid PHP running for too long, and cancelling the operation, you can use:Regenerate attachments 1-5:
https://YOURSITE/wp-admin/upload.php?regenerate_pdf_thumbnails=1®enerate_pdf_thumbnails_chunk_size=5
Regenerate attachments 6-10:
https://YOURSITE/wp-admin/upload.php?regenerate_pdf_thumbnails=1®enerate_pdf_thumbnails_chunk_size=5
And so on.
Forum: Plugins
In reply to: [PDF Thumbnails] Assigning a Title to generated PDF thumbnailsI forgot to update the version number in main plugin file, sorry. Should be up now.
Forum: Plugins
In reply to: [PDF Thumbnails] Assigning a Title to generated PDF thumbnailsHi,
That’s not a bad idea, I released a new update (version 0.0.4) that will name thumbnails as you described, PDF_NAME-thumbnail. This will name all new uploads. If you would like to automatically name existing files, you can use
get_post_thumbnail_id($pdf_attachment_id)
to find the thumbnail.I’m glad you like the plugin and would like to encourage you to click “Works” on the compability for WordPress 4.0, and to add a rating/review if you have the time.
Thanks.
Stian
Forum: Plugins
In reply to: [PDF Thumbnails] Nothing but error messagesNo problem. I understand that the installation can be cumbersome the first time, extact steps depends on your system, I’m linking to some resources below. The general process is as follows:
- Install ghostscript
- Install imagemagick, compiled with ghostscript support
- Install PHP extension for imagemagick (can use pecl)
- Restart web server for changes to take effect
Debian / Ubuntu
sudo apt-get install ghostscript php5-imagick
sudo service apache2 restart
Windows
How to install imagemagick on windows 7
How to install, test, convert, resize PDF using ImageMagick, Ghostscript, Windows Vista/7 x64
OSX
Installing ImageMagick on Mac OSX for PHP and MAMP
Test installation
To verify that your system is ready to generate thumbnails:
- Create a file named test.php in your web root with the following content:
<?php phpinfo();
- Open
https://YOUR-SITE/test.php
in your web browser - Search for “imagick” and verify that “ImageMagick supported formats” contains “PDF”.
Forum: Plugins
In reply to: [PDF Thumbnails] Nothing but error messagesTwo weeks since last message, assuming issue was resolved.
Forum: Plugins
In reply to: [PDF Thumbnails] How to implement in themeThe thumbnail is stored on the PDF attachment, is it possible that you are trying to get a thumbnail for a normal post?
An easy way to test if thumbnails are working is to add the code you posted to single-attachment.php and open a PDF-attachment to verify that thumbnail is shown.
You can also use
get_the_post_thumbnail($pdf_attachment_id)
if you know the attachment ID.If this does not work, I need some more information to go on, viewing the entire template file in would be helpful.
- Debian/Ubuntu: