Theme development in wordpress

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

  1. style.css // which controls presentation of pages
  2. functions.php //
  3. 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

  1. import js and css using enque function
  2. we can enable theme features like sidebar, menu, post format, thumbnail etc.
  3. 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

  1. style.css // this file must be include and have information about theme without information theme will not availble for install.
  2. 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.
  3. index.php // this is the main template file of theme
  4. comments.php // hanling comments part of posts
  5. front-page.php // front page for site
  6. home.php // front page by default when we set static front page then this page will show our latest posts here.
  7. single.php // this will display when we want to see post details.
  8. 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.
  9. page.php // When a particular page is queried
  10. category.php // When a category is queried
  11. tag.php // When a tag is queried
  12. taxonomy.php // When a term is queried by custom taxonomy
  13. author.php // Used when author is queried
  14. date.php // Used when date or time is queried
  15. archive.php // Used when category , author , date data to show
  16. search.php // Displying search results
  17. attachment.php // Used when viewing single attachment
  18. image.php //for viewing single image attachment if not available this file then attachment.php will be use
  19. 404.php // display not found page , if requested page or post not found then this template will use

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow by Email
LinkedIn
Share
Instagram