What I'm saying is that you must use the code above in the right section of the template. You can't just paste it in anywhere, as it won't work. The $listing_id variable is defined within a certain scope of the template's execution, which is why I need to see the exact entire template code that you are currently using, to know what is wrong.
This sounds like a simple programming error, but without seeing the template, I can't tell you what the exact problem is. I know you posted it already, but since you have changed it afterward, I need the exact, current copy.