Examining the Main Index and The Loop
Your theme is required to have only two files. The first is style.css. The other is a main index file, known in WordPress as index.php. The index.php file is the first file WordPress tries to load when someone visits your site. Extremely flexible, index.php can be used as a stand-alone file or include other templates. The Main Index template drags your blog posts out of the MySQL database and inserts them into your blog. This template is to your blog what the dance floor is to a nightclub — where all the action happens.
The filename of the Main Index template is index.php. You can find it in the /wp-content/themes/twentyten/ folder.
The first template tag in the Main Index template calls in the Header template, meaning that it pulls the information from the Header template into the Main Index template, as follows:
<?php get_header(); ?>
Your theme can work without calling in the Header template, but it will be missing several essential pieces — the CSS and the blog name and tagline, for starters.
The Main Index template in the Twenty Ten theme calls in three other files in a similar fashion:
- get_template_part( ‘loop’, ‘index’ ); — this function calls in the template file named: loop.php.
- get_sidebar(); — this function calls in the template file named: sidebar.php.
- get_footer(); — this function calls in the template file named: footer.php.
Each of these three functions and template files is covered in upcoming sections of this chapter.
Get WordPress® All-in-One For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.