Community Forums › Forums › Archived Forums › Design Tips and Tricks › PHP Error
- This topic has 6 replies, 2 voices, and was last updated 4 years, 9 months ago by
PunkUK.
-
AuthorPosts
-
August 29, 2018 at 1:36 pm #222796
PunkUK
MemberHi, can anyone please explain why I am getting this error:
pro/functions.php on line 341Notice: Trying to get property of non-object in /home/chocol37/public_html/myersfitness.co.uk/wp-content/themes/infinity-pro/functions.php on line 341
Here is the php:
/** Add the featured image section */
add_action( 'genesis_after_header', 'full_featured_image' );
function full_featured_image() {
if ( is_front_page() ) {
echo '<div id="full-image"></div>';
}
elseif ( is_singular( array( 'post', 'page' ) ) && has_post_thumbnail() ){
echo '<div id="full-image">';
echo get_the_post_thumbnail($thumbnail->ID, 'header');
echo '</div>';
}
}When I use this in Altitude Pro it is fine.
Many thanks to anyone who can help.
http://php, hero image, altitude proAugust 29, 2018 at 6:15 pm #222802Victor Font
ModeratorSince you didn't post line numbers, which line is causing the hiccup?
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 29, 2018 at 11:26 pm #222805PunkUK
MemberHi Victor,
Thank you so much for replying. The line is: echo get_the_post_thumbnail($thumbnail->ID, 'header');
Many thanks.
August 30, 2018 at 7:17 am #222809Victor Font
ModeratorWhere are you initializing $thumbnail->ID?
You're passing an object element as a parameter, but you're not initializing the object anywhere. The error is correct.
This is how to use that function: https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 30, 2018 at 12:32 pm #222816PunkUK
MemberHi Victor,
Thank you again for your reply. I wish I could answer your question but I don't know the answer. I used this code on the Altitude Pro theme and it works fine but for some reason I get this error with Infinity Pro.
If you have any suggestions I would most grateful. Would help to see the full functions PHP?
August 30, 2018 at 12:59 pm #222819Victor Font
ModeratorIf that seems to work in Altitude Pro, then you are either not hitting the condition to trigger the notices, PHP notices are turned off, or you missed copying the code where that parameter is initialized. There's no way that code should work anywhere without initializing the parameter.
The theme has nothing to do with whether that code works or not.
You are passing an uninitialized object as a parameter to the WordPress get_the_post_thumbnail() function. The first parameter is either the post id or null. The default is null.
I would go back to wherever you got the code from and see what you're missing. I can't help you further without access to the back-end of the site.
If you can't figure this out, you may have to hire a developer to help you.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 31, 2018 at 1:23 am #222839PunkUK
MemberNo Problem. I have fixed it.
-
AuthorPosts
- The topic ‘PHP Error’ is closed to new replies.