wordpress - Php error "Undefined variable:post" when using "get_post_thumbnail_id($post->ID)" -


i have line of php thumbnail image in custom wordpress widget:

$footer_recent_thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->id), 'footer-recent-thumbnail' ); 

it produces 2 php errors:

notice: customwidgets.php:75 - undefined variable: post notice: customwidgets.php:75 - trying property of non-object 

how can resolve this? same php use thumbnail on blog , doesn't give error there.

my guess code in function, so:

function dosomething($someparams) {      // ...      $fotoer_recent_thumb = // .....      // ... } 

in case, $post not exist in scope, , must imported adding following line inside function:

global $post; 

alternatively, , more cleanly, pass parameter.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -