WordPress themes contain PHP template files, and those files must be named in a certain way in order for them to be seen and used by the software itself. While custom PHP template file can be created outside this mandatory file structure, it’s important to focus on creating these essential files first in order to ensure that every page within an installation can be properly displayed and used by the site’s readers.
Every theme must contain a style.css file; this file not only helps turn plain XHTML elements into vibrant containers for content, but also contains basic header information at the top of the file which identifies the theme’s name, author, version, homepage, and keywords. Without this file, and the header information it must include, the theme will not show up in the WordPress Dashboard and therefore will not be available for activation and use. For more information on what needs to be placed into this files, novice developers can visit the WordPress Codex for the series of lines and information they must customize to their theme.
The next files which should be created as part of the new theme should be the separate header and footer PHP template files. Almost every WordPress theme uses these files to split off the header and footer from the main content area, making it easy to alter those files and have the changes be reflected universally, rather than editing every content-containing file separately over a longer period of time. These files are pretty straightforward, but here’s a primer on each:
- header.php should contain everything from the DOCTYPE tag to the end of the page’s navigation. This means that all <head> tag information, meta tags, <title> tag variables, and other information must be included in the site’s header. This template file also must contain the <?php wp_head(); ?> tag, which places valuable WordPress version-sharing information, and other website information, within the head of the document. It must be placed before the closing </head> tag.
- footer.php begins when the page body closes, and includes any information that a user wishes to contain in the footer. This can be a content-rich footer, which is a currently-trendy way of closing the document, or simply a copyright statement and some valuable links to other resources. It must close the <body> tag as well as the HTML document itself, using the </html> tag before the end of the file.
Once these two files are created, they can be simply included into all of the other theme’s content-area PHP template files using WordPress PHP variables. It’s an exceedingly easy way to create a dynamic template, and users will be pleased with not having to learn extensive PHP inclusion coding in order to make the header and footer appear automatically on every page. With the header and footer complete, a new list of files must be created to display WordPress category, page, and post content to site readers. Those files include:
- archive.php
- category.php
- index.php
- page.php
- search.php
- single.php
With the theme’s content files created, there is one last required theme file and one more optional one which can be added to the containing folder. The required file (for the vast majority of WordPress installations) is the sidebar.php template. This file is pretty self-explanatory, and it contains the entire theme’s sidebar information. It can be included into all of the other content-specific template files by using a simple, WordPress-exclusive PHP variable. It simply gets placed within the sidebar <DIV> tag and that’s all there is to it.
With all of the actual content display template files created, there is one last thing which can be added to the theme’s containing folder. That is the functions.php file which serves not to display content, but rather to add functionality and alter how content is created, displayed, or interacted with. This file is sort of like a theme-specific listing of plugins; anything placed into functions.php will only modify the site’s operation while the relevant theme is selected. For most novice developers, this file is extraneous and will likely not need to be included with a theme. However, it’s a good idea to create a blank version of the file so that it can be easily added to at a later date, especially as theme development skills are joined by PHP coding skills which may prompt a user to add functions to the site.
This is a part of The Anatomy of a WordPress Theme tutorial.
The post The Anatomy of a WordPress Theme – Theme Files and Typical File Structure appeared first on Tutorial Mini.
Related posts:
- The Anatomy of a WordPress Theme – Theme Location
- The Anatomy of a WordPress Theme
- WordPress Basic – First Step With WordPress – Customizing Your WordPress Site
via Tutorial Mini http://tutorialmini.com/the-anatomy-of-a-wordpress-theme-theme-files-and-typical-file-structure/
No comments:
Post a Comment