In this theme, the Featured Image display on two places: on the top of each article (Post Page) and will be used as a Thumbnail Image (on both Index Page and Category Page).
Since I cannot always find images with high resolution, I don’t wanna some images display on Post Page (the resolution is 770*400) as Featured Image, but I want to the articles without Featured Image can have a Thumbnail Image (230*130 or 501*282, which can be displayed on Index Page and Category Page)
Can I use “custom fields” to achieve this object?
It looks like:
if I upload a Featured Image (surely the image’s resolution is 770*400), it will be displayed on Post Page, Index Page and Category Page (with small size);
but if I don’t upload a Featured Image, I can use “custom fields” to create something like “Big Thumbnail Image”,”Small Thumbnail Image”, and these images can be displayed as Thumbnail Image on Index Page and Category Page.
Can someone give me a reply? Thank you so much!
Hi Zhenyu,
Apologies for the delay in replying to you.
To resolve this issue, you can try this solution.
The code bellow will automatically check your thumbnail image size. If the thumbnail image is smaller than 770*400, it will not show on single.
– Open content-single.php in /wp-content/themes/dw-focus/content-single.php
– Replace following code – line 16
<?php if( has_post_thumbnail() && ! has_post_format('video') && ! has_post_format('audio') && ! has_post_format('gallery') ) : ?>
with:
<?php
$display_thumbnail = true;
$thumbnail_size = getimagesize( wp_get_attachment_url( get_post_thumbnail_id() ) );
if ($thumbnail_size[0] < 770 || $thumbnail_size[0] < 400) {
$display_thumbnail = false;
}
?>
<?php if( has_post_thumbnail() && ! has_post_format('video') && ! has_post_format('aud
Thank you so much! but the code seems not shown completely? it ended with:
Dear Dominic, the code seems not shown completely (it ended with “has_post_format(‘aud”), can you give me the full code? Thank you so much.
I’ve tried replace
<?php if( has_post_thumbnail() && ! has_post_format(‘video’) && ! has_post_format(‘audio’) && ! has_post_format(‘gallery’) ) : ?>
with
<?php
$display_thumbnail = true;
$thumbnail_size = getimagesize( wp_get_attachment_url( get_post_thumbnail_id() ) );
if ($thumbnail_size[0] < 770 || $thumbnail_size[0] < 400) {
$display_thumbnail = false;
}
?>
<?php if( has_post_thumbnail() && ! has_post_format(‘video’) && ! has_post_format(‘audio’) && ! has_post_format(‘gallery’) ) : ?>but it seems doesn’t work..
With new code:
<?php
$display_thumbnail = true;
$thumbnail_size = getimagesize( wp_get_attachment_url( get_post_thumbnail_id() ) );
if ($thumbnail_size[0] < 770 || $thumbnail_size[0] < 400) {
$display_thumbnail = false;
}
?>
<?php if( has_post_thumbnail() && ! has_post_format('video') && ! has_post_format('audio') && ! has_post_format('gallery') && $display_thumbnail ) : ?>
it works. Thank you so much!
Dear Dominic:
The code works and it achieved my object, but an other error occurred:
If I post an article without a Featured Image, it will display:
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/qizhenyu/www/demo/wp-content/themes/dw-focus/content-single.php on line 21
on the top of the article.
How can I fix it? Thank you so much!
I have checked on our demo and still work fine, you can send me username & password of your site (via private answer) for further checking.
Regards,
We have helped you resolve this issue, you can check your site now.
Thank you, but it seems that the issue is still exist, you can check on this article: https://clbchinese.org/2033.html
“Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/clbchinese/www/www/wp-content/themes/dw-focus/content-single.php on line 21”
still on the top of the article.
I checked your site as you mentioned previously. The problem on your site is caused by the cache, not bug. The site works fine for me at the moment, please check your site to handle the cache problem.
It works fine now, thank you so much!
Dear Dominic:
I have another site is facing this kind of issue, too. Can you tell me the specific method to fix the warning “Warning: getimagesize() [function.getimagesize]: Filename cannot be empty ” issue?
I’ve tried to copy the original theme files you revised to another site, the “Warning: getimagesize() [function.getimagesize]: Filename cannot be empty ” occur again.
Hi,
Please check your site now, I have help you resolve this issue.
Regards,
but I have another site with the same issue, can you tell me how to resolve this issue?
I’ve copied the content-single.php ob clbchinese.org to the other site, but the error still exist, the way to solve this issue is not about content-single.php?
You can provide username & password of your site that you mentioned here. I will check and help you resolve it.Regards,
please refer to the latest reply, thx!
Hi, I gave you the username & password in my latest reply. Can you help check my site? Thx
Please check your site, I have helped you resolve this issue.
You can open the content-single.php file then find / Replace the following code from line 20 to line 26.
<?php
if(has_post_thumbnail()) {
$attachment_src = wp_get_attachment_image_src( get_post_thumbnail_id() );
$display_thumbnail = is_array($attachment_src)
&& $attachment_src[1] >= 770
&& $attachment_src[2] >= 400;
}
?>
Hope this helps !
Thanks for your help, but I find it cause an other problem: even the feature image is 770*400 or larger, it will not display on the top of the article, you can refer to this article: http://demo.hkci.org.hk/1116.html
Hi, can you check this issue? Thx
The issue has been solved by replace wp_get_attachment_image_src( get_post_thumbnail_id() with wp_get_attachment_image_src( get_post_thumbnail_id(), ‘full’
Please login or Register to submit your answer
replied 11 years ago
Can someone give me a reply? Thank you so much!