Chapter 8: Conditional Display: Functions, Template Files, and Styling

Small, simple sites will have similar content on every page and post, with the same use of the loop, the same widget areas, and the same template tags and hooks. Larger sites, however, which typically have distinct sections or require customization in different parts of the site, will need conditional content or styling. As with many things WordPress, there is more than one way to deal with this. In some cases conditional tags within template files will be the way to go, in others it might be different template files for different areas of the site, and in some cases, where it is styling that needs to change and not content, CSS targeting specific areas of the site will be needed.

This chapter looks at different scenarios that require conditional code and the options you have to make it work. You'll learn when you might use each of the possible approaches and look at some examples of sites and themes that use conditional content and styling, and the code used to achieve it.

Conditional Content: When It Applies

The following are some scenarios in which you would need to use conditional code in a site:

• Some areas of the site include an element not displayed on the rest of the site, such as a home page banner image, or a widget area used in just one section of the site.

• Sections of the site have their own navigation, either connected to the main navigation or in a sidebar—or even within the main content ...

Get WordPress: Pushing the Limits now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.