admin管理员组文章数量:1130349
I'm trying to get the thumbnail of my featured image to display on my home.php (blog) page.
It is displaying fine, but when debugging mode is turned on, I get this error:
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/wpflat/wp-content/themes/wpflat/content-blog.php on line 2
My code is
<a href="<?php the_permalink();?>"><?php echo get_the_post_thumbnail($page->id, 'thumbnail'); ?></a>
How do I solve this issue?
I'm trying to get the thumbnail of my featured image to display on my home.php (blog) page.
It is displaying fine, but when debugging mode is turned on, I get this error:
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/wpflat/wp-content/themes/wpflat/content-blog.php on line 2
My code is
<a href="<?php the_permalink();?>"><?php echo get_the_post_thumbnail($page->id, 'thumbnail'); ?></a>
How do I solve this issue?
Share Improve this question edited Apr 24, 2014 at 7:15 Pieter Goosen 55.5k23 gold badges117 silver badges211 bronze badges asked Apr 24, 2014 at 7:09 user50763user50763 53 bronze badges 1 |1 Answer
Reset to default 2I believe from your error that you are using this code inside the loop. You should be using the_post_thumbnail(). The code you are using is used outside the loop.
EDIT
It is always good practice to always first check if you have a thumbnail to display
So you should use
<?php if(has_post_thumbnail()): ?>
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail( 'thumbnail'); ?>
</a>
<?php endif; ?>
I'm trying to get the thumbnail of my featured image to display on my home.php (blog) page.
It is displaying fine, but when debugging mode is turned on, I get this error:
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/wpflat/wp-content/themes/wpflat/content-blog.php on line 2
My code is
<a href="<?php the_permalink();?>"><?php echo get_the_post_thumbnail($page->id, 'thumbnail'); ?></a>
How do I solve this issue?
I'm trying to get the thumbnail of my featured image to display on my home.php (blog) page.
It is displaying fine, but when debugging mode is turned on, I get this error:
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/wpflat/wp-content/themes/wpflat/content-blog.php on line 2
My code is
<a href="<?php the_permalink();?>"><?php echo get_the_post_thumbnail($page->id, 'thumbnail'); ?></a>
How do I solve this issue?
Share Improve this question edited Apr 24, 2014 at 7:15 Pieter Goosen 55.5k23 gold badges117 silver badges211 bronze badges asked Apr 24, 2014 at 7:09 user50763user50763 53 bronze badges 1-
You need to show more code. What is
$page?– vancoder Commented Apr 24, 2014 at 23:25
1 Answer
Reset to default 2I believe from your error that you are using this code inside the loop. You should be using the_post_thumbnail(). The code you are using is used outside the loop.
EDIT
It is always good practice to always first check if you have a thumbnail to display
So you should use
<?php if(has_post_thumbnail()): ?>
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail( 'thumbnail'); ?>
</a>
<?php endif; ?>
本文标签: Trying to get property of nonobject error with thumbnail
版权声明:本文标题:Trying to get property of non-object error with thumbnail 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749138412a2321768.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


$page?– vancoder Commented Apr 24, 2014 at 23:25