Very often in customizing themes, I run into the need for simple if/then/else logic. Maybe I want to display the author name only in certain categories, or I need a certain plugin to display output only on certain posts or pages, for example. Adding a quick bit of PHP makes these variable items very easy. Here’s the code:
<?php if (in_category('67')) { ?>
<p>Blue</p>
<?php } else { ?>
<p>Red</p>
<?php } ?>
In plain English, this code says: if the post is in category #67, display ‘Blue’, otherwise, display ‘Red’. I used a conditional tag for my if statement. You can read more about using WordPress conditional tags here.
Need to have random color schemes for a site or maybe a random background image? Use this bit of PHP to load a random CSS stylesheet each time a user visits a site.
This is a handy little bit of PHP that randomizes images from a folder using PHP.
This is so simple and something people often overlook, so their footer’s copyright date still shows the year they set up the theme in the first place.
Content sliders are all the rage, and this is a great tutorial on how to add one type of JavaScript slider to your site.