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 comment_count,ID,post_title,... [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]
Adding an admin page near “Setting/Plugins/Users”
October 22, 2008
WordPress have a lot of very nice function which allows you to quickly add menu page in the admin dashboard. But sadly, no function was created to add an admin page near the “Setting/Plugins/Users”. Here’s a nice code to easily add an admin page there. This is a function that will create a new admin page near “Setting/Plugins/Users” in your WordPress dashboard. Paste the code below in your functions.php file. define ('TWEAK_MENU_BEGIN', 25); define ('TWEAK_MENU_END', 40); function add_tweak_menu_page($name, $capability,... [Read the full story]
Display any rss feed on your WordPress blog
October 22, 2008
Do you ever wanted to be able to display any rss feed on your WordPress blog? If yes, here’s a simple code that will get that thing done. Do you know that WordPress have a function, called wp_rss(), which is nothing else than a built-in rss reader? Here’s the simple code to add where you want the rss to be displayed (Personally, I’d use my sidebar, my footer or a page template): <?php include_once(ABSPATH . WPINC . '/rss.php'); wp_rss('http://feeds.feedburner.com/livexp', 3); ?> Let’s have a quick look to the... [Read the full story]



















