Here we are going to learn about WordPress theming. How can we create or develop own theme ? Here we discuss about some main ideas about WordPress theme.
So when we install WordPress , we can find some default theme in wp-content/themes directory. so all WordPress themes are in wp-content/themes directory .
WordPress have some rules, how to develop new theme and also have files structure.
Note: You must have some basic knowledge of html/css/jquery
Every theme has 3 main files
- style.css // which controls presentation of pages
- functions.php //
- template file (like index.php) // for handling template files
1.style.css
In this file, we can see some comments from starting of files. these comments are very important for theme development because these are not simple comments, these comments has information about theme, like theme name, version, features and every theme must have unique comments.
lets see sample themes comments
style.css /* Theme Name: phpguruji Theme URI: https://phpguruji.com/themes/phpguruji Author: phpguruji Author URI: https://phpguruji.com/ Description: phpguruji is the bloging theme Version: 1.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: black, brown, orange,translation-ready Text Domain: phpguruji This theme, like WordPress, is licensed under the GPL. Use it to make something cool, have fun, and share what you've learned with others. */
2. functions.php
This file is just like a plugin, using this file we can extend our theme functionality and can reuse the code. this file automatically loaded during WordPress initialization.
here is main task , we can enable using functions.php
- import js and css using enque function
- we can enable theme features like sidebar, menu, post format, thumbnail etc.
- we can give custom styling, design , color , theme options etc.
Note: we will discuss about all necessary functions for theme development
3. Template files
Template files are combination of php, html, css and WordPress functions, When user visit our website pages that time template files are present the requested page with the help of template files. Theme have many template files but if we have only index.php then all the pages will generated by index.php.
we need to know about other template files and how can we use it
- style.css // this file must be include and have information about theme without information theme will not availble for install.
- rtl.css // this file for localization purpose when we want add multi language in theme , this will set direction of text from right-to-left.
- index.php // this is the main template file of theme
- comments.php // hanling comments part of posts
- front-page.php // front page for site
- home.php // front page by default when we set static front page then this page will show our latest posts here.
- single.php // this will display when we want to see post details.
- single-{post-type}.php // this display custom post type single post data. suppose we have book post type then sinlge-book.php will display single data for book post type.
- page.php // When a particular page is queried
- category.php // When a category is queried
- tag.php // When a tag is queried
- taxonomy.php // When a term is queried by custom taxonomy
- author.php // Used when author is queried
- date.php // Used when date or time is queried
- archive.php // Used when category , author , date data to show
- search.php // Displying search results
- attachment.php // Used when viewing single attachment
- image.php //for viewing single image attachment if not available this file then attachment.php will be use
- 404.php // display not found page , if requested page or post not found then this template will use