Magnetism and electricity are aspects of electromagnetism, the force and effects created by electric charges. Electric charge, mass, spin, etc., are basic properties of matter.
If you look at an immobile electric charge, you will see electrical effects from it. If you look at a moving electric charge, you will see magnetic and electric effects from it. And because motion is relative, you could be seeing purely electrical effects, whereas someone on a high speed train that’s passing by you could see magnetic effects from the charge you’re holding (immobile) in your hand.
Certain atoms have a magnetic field as a result of how the electrons (charges) orbit the nucleus inside the atom. If you have a material where these atoms “line up” their magnetic orientation / electron spin, then the material as a whole will have magnetic properties, the “added up” effects from all the individual atoms. Heat makes atoms vibrate with energy and in general they will rotate and reorient and their magnetism will be in a random direction and will cancel out rather than adding up.
Earth’s magnetic field, the Sun’s magnetic field, Jupiter’s, etc., all of these are created through different mechanisms, but they do all come down to the movement of charged particles inside the planet somewhere.
Latest Answers