OK. Let’s see …
How do WordPress themes work?
When you are creating a website, basically you are using an HTML or PHP code to get a web browser to display your content. The traditional site building methods will require:
- core HTML or PHP files to create the content itself
- cascading style sheets (CSS files) used to tell the browser how that content should look
- script files (Javascript, jQuery, etc) used to create interactivity and to add various different features to the given page
It means that every single page must be meticulously written to display the correct HTML, PHP, CSS, etc for everything to work properly. When you want to make some changes, each and every page must be modified individually. Which is boring and time consuming …
The content management systems have changed the situation creating a clear separation between style and content. The style is defined by templates while the content is stored in a database. As I already mentioned earlier, the final outcome visible on the front-end is nothing else, but a dynamic template populated with database entries.
What does it mean? It means that you can change how the content is displayed without actually touching the content itself. And this is the core operating principal of any content management system (WordPress, Drupal, Joomla, Magento, etc) and any WordPress component (themes, plugins, widgets, etc).
Long story short: a WordPress theme is nothing else, but a series of templates, style sheets, and scripts contained within a dedicated folder. When you add a new theme to your WordPress site, the given dedicated folder will be added to the default WordPress theme folder. These template files are included into a hierarchically organized structure (something called WordPress template hierarchy).
Whenever you perform a given action that will create a new database entry, WordPress will identify the corresponding template file in your theme folder in order to generate the proper visual outcome. For example, when you create a new post, WordPress will analyze the regular post template that is associated with your current theme, in order to build up the correct layout, to implement the included formatting rules, etc for your new post. If you choose to create a new sales page, WordPress will identify and use the page template … And so on …