Before creating any theme in wordpress, you have to understand wordpress file and directory structure that how it will store them and used in building a web pages in our website.
Everyone knows wordpress is popular CMS for creating websites, so you have to understand how it works, debug and customized. The information about these all thing can help your website to optimize your site.
Basically wordpress come with three basic folders and some core files which helps to setup website and manage some core functionality of website. The three folders and files are here.
.htaccess, wp-config.php, index.php, wp-settings.php, wp-login.php, wp-signup.php, wp-activate.php and other files.
- .htaccess file will handle your site permalinks and redirects, basically it is server configuration file.
- wp-config.php will connect your database with site and store sites global configuration settings.
- index.php – this is the file where all other files are initialize and executed when user page is requested
- wp-settings.php – this file store the setting of wordpress that how to handle all user requests.
- wp-login.php, wp-singup.php and wp-activate.php files are related to user login and sigup.
Now understand the folder sturcture.
- wp-admin – this folder contains all the core files related to admin panel. From this admin panel you can control your pages, posts, themes, plugins, users and other many more settings to website.
- wp-includes – this folder is the core of wordpress. All the action and filters are stored here. It tells wordpress how to perform user actions and settings on front-end. All settings related to theme, plugin and wordpress admin panel are stored here. User can not change here any files and folders.
- wp-content – this is the folder where user can work and make changes in themes and plugins. This is folder where user can insert no of themes and plugins respectively in themes and plugins folders which are already created by wordpress.
This is the core file and folder structure of wordpress. Now we move on wordpress theme structure, how it works and customized.
WordPress store all themes in wp-content themes folder. wordpress theme is just like HTML webpages which coded with PHP code. So you have to little knowledge of PHP language. so lets start understand the theme structure.
- style.css – A stylesheet file which define your theme and holds all the formatting and style of your theme.
- index.php – This is the main file of theme which combined with all other files.
- footer.php – This file holds the footer section files.
- sidebar.php – This file holds the sidebar section which are generally used for short information about website. User put widgets in this section like Recent Post, Custom Menu, Archives and much more… We learn more about sidebar and widget in their respective posts.
This are the basic files of any wordpress theme structure. There are other files also find in theme.
- functions.php – This file store the setting of theme to customize it, like you can set layout of theme, define thumbnail sizes for images, register any extra sidebar or custom post type and many more.
- search.php – This file handles the search result of website. User can enter any text in search form, the query will executed related to that shows the result on this search page.
- page.php – This file handle the behaviour of individual pages which are created from admin panel
- single.php – This is blog post which handle the individual posts
- comments.php – This file executed code of comments which are posted on particular post.
- archive.php – This file handles the archive results, like category, tags, authors posts all are executed on this file.
- 404.php – This file executed when error occured when accessing pages or posts which are not available in site.
These all are the files in particular theme. There are other templates files also created according to theme requirement. You can view the wordpress template hierarchy here. Also wordpress provide default theme with its installation like twentyfourteen, twentyfifteen and twentysixteen. You can refer them also.