Currently Browsing: Scripts & Code

Simple PHP if/then/else code

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.

Load Random Stylesheets in WordPress

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.

Randomize Multiple Images with PHP

This is a handy little bit of PHP that randomizes images from a folder using PHP.

Display current year for copyright in footer

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.

How to add a featured content slider

Content sliders are all the rage, and this is a great tutorial on how to add one type of JavaScript slider to your site.

Next Entries »