As you're modifying your theme to accommodate different types of pages, you should also know about the CSS classes that WordPress will put into your theme. If you look carefully at the code we've been using, you'll see these two functions:
- body_class(): For example, in the header.php file, the exact line is <body <?php body_class(); ?>>
- post_class(): For example, in the content-page.php file, the exact line is <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> .
The body_class() function adds a whole bunch of classes to the body tag, depending on the page you're viewing. For example, the main page of my site has the following classes in the body:
<body class=" home blog custom-background">
My Some Spanish Dishes single post page's body tag looks like the following:
<body class=" single single-post postid-41 single-format-standard custom-background">
If I wanted to style anything differently on any of my pages, I could do it largely via CSS, without having to create another template.
The post_class() function does something similar with the individual post's div, giving it different classes depending on the characteristics of the post itself. For example, my Some Spanish Dishes post's tag has the following class:
<article id="post-41" class="post-41 post type-post status-publish format-standard hentry category-uncategorized">
Further more, my sample page post tag has the following class:
<article id="post-2" class="post-2 page type-page status-publish hentry">
Using these classes in my style sheet, I could style each post differently depending on its category, tag, post type, and so on. Keep this in mind as you design your theme. This becomes extremely important when working with theme frameworks further down the road. Although modifications inside PHP files are allowed, most of the time, you can customize the design of your whole site just by working in the CSS and tweaking various classes (both the native ones in WordPress and the new ones that the framework uses). Situations where a whole new site working on a theme framework gets built purely in CSS files are not uncommon.