I use a modified version of the following script:
It works fine when I use the code directly in my Sidebar file of the activated theme but I want to use it in a Plugin / Widget but the script can not receive the required Post ID. $post->ID is empty.
Notice: Undefined variable: post
Notice: Trying to get property of non-object