Zhenyu QI
asked 10 years ago

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.

Zhenyu QI
replied 10 years ago

Can someone give me a reply? Thank you so much!

5 Answers
Zhenyu QI
answered 10 years ago

Can someone give me a reply? Thank you so much!

DominicStaff
answered 10 years ago

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
Zhenyu QI
replied 10 years ago

Thank you so much! but the code seems not shown completely? it ended with:

Zhenyu QI
answered 10 years ago

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.

Zhenyu QI
answered 10 years ago

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..

DominicStaff
answered 10 years ago

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 ) : ?>
Zhenyu QI
replied 10 years ago

it works. Thank you so much!

Zhenyu QI
answered 10 years ago

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! 
 

DominicStaff
answered 10 years ago

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,

Dominic Staff
replied 10 years ago

We have helped you resolve this issue, you can check your site now.

Zhenyu QI
replied 10 years ago

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.

Dominic Staff
replied 10 years ago

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.

Zhenyu QI
replied 10 years ago

It works fine now, thank you so much!

Zhenyu QI
answered 9 years ago

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. 

DominicStaff
answered 9 years ago

Hi,
Please check your site now, I have help you resolve this issue.
Regards,

Zhenyu QI
replied 9 years ago

but I have another site with the same issue, can you tell me how to resolve this issue?

Zhenyu QI
replied 9 years ago

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?

Dominic Staff
replied 9 years ago

You can provide username & password of your site that you mentioned here. I will check and help you resolve it.Regards,

Zhenyu QI
replied 9 years ago

please refer to the latest reply, thx!

Zhenyu QI
replied 9 years ago

Hi, I gave you the username & password in my latest reply. Can you help check my site? Thx

DominicStaff
answered 9 years ago

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 !

Zhenyu QI
replied 9 years ago

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

Zhenyu QI
replied 9 years ago

Hi, can you check this issue? Thx

Zhenyu QI
answered 9 years ago

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’

Powered by DW Question & Answer Pro