Faking Multiple Templates with WordPress

Unlike other blog software like Movable Type, WordPress uses a single template system which might be a blessing or a boon to people. Some people find it easy to use, and some people find it over-simplified. It makes it hard to have different looks for different sections of the site. For example, having the sidebar on the main page but not on sub-pages. Here’s how to covercome that.

if ($single) {
// individual post contents
} else if ($cat) {
// categorical listing contents
} else if ($m) {
// monthly listing contents
} else if ($year) {
// yearly listing contents
} else {
// main page contents
}

It involves the use of WordPress built in boolean values, which are $single, $cat, $m and $year. The above code is the basic idea how to make use of the booleans to display different content in each type of page.

Tips are courtesy of ElasticDog. Visit the reference for some detailed examples on how to implement this.

Reference: ElasticDog

Looking to sell your car? Sell it with Carro.

10% discount when you renew your car insurance

Compare prices between different insurer providers and use the promo code 'PAULTAN10' when you make your payment to save the most on your car insurance renewal compared to other competing services.

Car Insurance

Paul Tan

After dabbling for years in the IT industry, Paul Tan initially began this site as a general blog covering various topics of personal interest. With an increasing number of readers paying rapt attention to the motoring stories, one thing led to another and the rest, as they say, is history.

 
 

Add a comment

required

required