How to run a Minecraft command?

I have no idea how to make so that if a specific entity goes above or somewhere else in a specific kind block the entity will run a command.

For example: a pig goes over a cake and if it goes over it creates particles.

I don’t know if it is with the execute and if or other. I’m good at command blocks, but not much of execute, I have no idea how to do it …

A little help pls?