PHP is a “programming language”. It’s not a templating language. You can’t copy and paste various snippets around places and expect them to continue to work exactly the same, because that’s not how programming works.
The PHP Code widget lets you execute PHP code. However, it doesn’t attempt to correct or fix your code. If the code was intended for one place, and you try to run it in some other place, then the code probably won’t work. The solution: Learn what the code does, how it does it, then fix your code.
Also, like it says in the FAQ:
I have code that works normally in a template but doesn’t work when in the widget?
Code in a template runs in the global context. Code in the widget will run in a function context. Make sure that you declare any global variables as global before attempting to use them.
Thread Starter
styzer
(@styzer)
Thanks for any help, I realize I’m diving into areas of the code that I don’t fully understand…
Thank you for the reply, Samuel, as I said, this is unknown for me.
1- I didn’t write that code, I would never attempt it – I tried to grasp PHP over the years, but it’s not something I’m able to process. Thankfully there are others who do understand it. That’s why I asked.
2- The plugin I use is not maintained and the author is nowhere to be found. I hope he’s OK, but I’ve tried all the avenues I had to contact him.
3- The plugin’s code only needs to be modified not reinvented, as it’s working, not just giving the proper link back to the posts. If it’s pulling their info, I didn’t understand why it’s not ALSO pulling their precise address correctly.
I wrote on a popular coding site and was given the impression that I should give up on it, but it didn’t make sense to me at the time. Obviously I’m very far from the mark.
Thank you for taking the time to reply, though.
Regards,
Andre
Yeah, the thing is, if you don’t really understand the code, then you really shouldn’t run it. If you don’t understand PHP, you really should not use this widget/plugin. PHP code that you don’t understand can be dangerous. Putting invalid code into the PHP Code Widget can break your site.
Basically, if you’re not really a PHP programmer, then I recommend not using my plugin and instead looking for a plugin more specific to your needs. Using code snippets is not wise. Honestly, using this plugin/widget is not wise. But I leave it around because many people find it useful.
Thread Starter
styzer
(@styzer)
I’m using it as it should be for a PHP shortcode and it’s perfect for this. I’m grateful I found your plugin. Nothing wrong there.
The question I had was obviously a question coming from my ignorance. Now I know, thank you.
Regards,
Andre