Components of the Default Theme


Studying the Default theme is a great way to learn about WordPress themes as designed by the WordPress development team and experienced users. As you work with WordPress, you'll find that most well-designed themes follow the basic structure of the Default theme.

The Default theme contains approximately 20 files, each of which has a specific function. Here's a quick overview of each file and its purpose.

Tips

  • The default theme was developed by Michael Heilemann. You can visit his blog and learn more about his work at binarybonsai.com.

  • If you're developing a theme that can't be viewed by the publicfor example, one on a testing serveryou can include the name of each file in the body of the file. Then, when you view a page, you can see which template controls each part of it. Remove the file names before using the theme on a publicly accessible blog.


Home page components

These core files together create the blog's home page (Figure 9):

  • index.php is the most important file. This file loads when a visitor views the home page of your blog. It calls header.php, sidebar.php, and footer.php to build the page. The most important code it contains is The Loop, which we explain on the previous few pages.

  • header.php contains standard information for the head section of any web page: document type declaration, character set, title, styles, and a call to style.css. It also opens the body section and includes the content of the header that appears at the top of your blog pages.

  • sidebar.php handles everything you see in the narrow right column. It includes a search form, optional author information, introductory text for category and date archives, links to pages, categories and archives, your blogroll or links list, and a section called meta with a login link and other items. PHP code controls which items are displayed under various circumstances.

  • footer.php adds the powered by WordPress and RSS links, an optional page load timer, a comment by the designer of the theme, and the closing tags for the page.

  • style.css contains cascading style sheet code used to display your blog pages. It begins with the name and description details for the theme, then provides typography, color, margin, border, and other display settings. It ends with a comment from the designer.

Figure 9. The file, index.php, which includes The Loop, calls header.php, sidebar.php, and footer.php to build the home page.


Other blog entry template files

These files also display blog entries or related comments:

  • single.php provides the content and layout of the page displaying full text for a single post (Figure 10).

    Figure 10. The single.php template produces a page like this one. Note that some of its content comes from other template files, like header.php, comments.php, and footer.php.

  • archive.php provides the content and layout of pages displaying entry archives by date or category.

  • comments-popup.php displays the form that allows visitors to leave comments.

  • comments.php displays various messages related to comments. For example, it might advise that comments are closed or that the visitor must log in to enter a comment.

  • search.php provides the content and layout of the page displaying search results (Figure 11).

    Figure 11. The search.php template displays search results.

  • searchform.php creates the search form that appears in the sidebar and elsewhere.

  • attachment.php displays a special attachment page when you click the link for an attachment in a post. If it's an audio attachment, clicking the audio icon plays the audio. If it's another type of attachment, clicking the attachment link downloads the linked file.

Page templates

WordPress's Page feature, which we discuss in detail in Chapter 3, displays Web pages of information from your WordPress MySQL database other than blog entries.

The Default theme has three of these templates:

  • page.php provides the default content and layout of stand-alone Pages. Use this template to create Pages with whatever static information you want to display.

  • archives.php is a template you can use to create a special archive Page. It builds a Web page that lists blog archives by date and category.

  • links.php is a template for creating a special links Page. It builds a Web page that lists all links by link category (Figure 12).

    Figure 12. WordPress can create a links page automatically if you create a blank page using the links.php page template.

To use these templates, you must choose the template from the Page Template menu when using the Write Page administration panel (Figure 13).

Figure 13. Choose the template you want to use from the pop-up menu.


Tips

  • The Archives and Links Page templates (archives.php and links.php) do not include The Loop. As a result, Pages based on these templates do not display any title or content text you may have entered when creating the Page.

  • We tell you more about creating Pages and managing links in Chapter 3.


Administrative files

These files are used internally by WordPress for administrative tasks.

  • functions.php is used for modifying the theme's header colors, as discussed in Chapter 1. You should not edit this file unless you have a very good knowledge of PHP.

  • screenshot.png is a thumbnail image for the theme. It appears in the Themes administration panel (Figure 14).

    Figure 14. The screenshot.png file appears in the Themes administration panel.

  • 404.php displays a formatted error message if a visitor attempts to view a page that does not exist and the server returns a 404 Not Found message.

  • images contains images for the default theme's appearance. The header-img.php file contains the programming to allow you to change the default theme's colors through the Header Image and Color section in the Presentation administration panel.

Tip

  • You can learn more about creating a custom Error 404 page at codex.wordpress.org/Creating_an_Error_404_Page.





WordPress 2. Visual QuickStart Guide
WordPress 2
ISBN: 0321450191
EAN: 2147483647
Year: 2004
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net