Posts
31 Jan 2013
It's easy to add themes to your website and allow your visitors to customise their experience. This post will guide you through implementing theme support on your website using PHP, CSS and cookies.
There are a few requirements of a theming system:
- Setting up your CSS files
- Showing a list of themes
- Allow the user to select a theme
- Include the selected theme styles
Setting up your CSS files
This method is designed around the idea of placing common styles in a file named *common.css *and placing theme specific styling in other CSS files. The filename of these files will become the theme name, like so:
- red.css is displayed as Red
- dark-blue.css is displayed as Dark Blue
- salmon.css is displayed as Salmon
For this example, the CSS files are placed in a top level folder named styles. Feel free to update this by changing the value of the $folder variables in the PHP functions.
Notes
Themes aren't suitable for every website, so use them wisely to allow for customisations that suit your visitors' needs. Also, don't forget to ensure your default theme remains usable, including suitably sized text and clear link styling.
Brendan Murty