Use multiple custom headers on a WordPress theme

October 24, 2008

Do you ever wanted to have multiple headers on your WordPress blog? If yes, here’s a clear and concise tutorial that will help you to get themost out of your blog headers! The first thing to do is to create header files. Create as many different headers as you want. In this exemple, I have created 3 custom headers from my theme default file header.php, names headercontact.php, headergallery.php and headerdefault.php. By using the php include() function and WordPress conditional tags, we can define custom headers easily. Replace... [Read the full story]

How to remove ads for registered users

October 22, 2008

Hiding ads for registered users is a good idea since it can help you to decrease the risk of being smart-priced by Adsense. To achieve this, we just have to use the is_user_logged_in() function, which returns true is an user is logged in. This recipe is very easy to use, just paste the following code anywhere on your theme. if (!is_user_logged_in()) { // Insert Adsense (or whatever) code here }  Read More →

Set post expiration date/time on your WordPress

October 22, 2008

Do you regret that WordPress haven’t a feature to publish a post during only 2 days, or one week? Here is a very nice code that you can use in your WordPress theme, to enable the possibility of creating post expiration based on date and time. Edit your theme and replace your current WordPress loop by this “hacked” loop: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> $expirationtime = get_post_custom_values('expiration'); if (is_array($expirationtime)) { $expirestring... [Read the full story]

Get most commented posts of the week

October 22, 2008

To achieve this hack, we have to make a custom SQL query by using the $wpdb object. Let’s start by creating 3 php variables: The first one is the number of days between today and X days ago, the second is today’s date and the last one is today’s date – X days. <?php $days = 7; //To fetch posts published during the last 7 days $today = date("Y-m-d H:i:s"); //Today's date $daysago = date("Y-m-d H:i:s",strtotime(date('Y-m-j H:i:s')) - (7 * 24 * 60 * 60)); //Today - $days $result = $wpdb->get_results("SELECT... [Read the full story]

Create a page to display a random post

October 22, 2008

Your blog have probably a lot of posts that your readers haven’t read yet. Why not creating a page and display a random post on it? Here’s an easy way to do it. The first thing to do is, of course, to create a page template. Once done, paste the following code in your new page template: <?php query_posts(array('orderby' => 'rand', 'showposts' => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?> // WordPress loop, your random post will appear here endwhile; endif; ?> That’s... [Read the full story]