Wordpress – List Scheduled Posts

If you ever wanted to show you readers posts that are scheduled to be published, here’s how to do it.

<?php
$result = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($result->have_posts()) {
    while ($result->have_posts()) : $result->the_post(); ?>
        <?php the_title(); ?>
    <?php endwhile;
}
?>

WordPress – Disable Auto Save

WordPress’s Auto-Save feature is a really nice but there are some drawbacks… this feature increases your database usage. So for those of you that are on really bad shared hosting accounts or just want to turn it off, here’s a quick way of doing it.

Open and insert the following line in your wp-config.php file.

define('WP_POST_REVISIONS', false);

Another method is to remove all of the entries from the database from time to time. You can do tun this query to do it::

DELETE FROM wp_posts WHERE post_type = "revision"; 

Migrate Wordpress to a new Server or Directory

If you decide to change the URL or link location of your WordPress Blog due to a new domain or moving to a sub-directory, here are some simple steps that should be done to ensure proper migration without breaking links.

To update WordPress options with the new blog location, use the following SQL command:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.olddomain.com', 'http://www.newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.com', 'http://www.newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.com', 'http://www.newdomain.com');

Wordpress – List your most popular Posts

This function below creates a list of links of the top commented posts on your Wordpress blog.

<?php
function listPopularPosts() {
    global $wpdb;
    $strBuidler = '';
	
    $result = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
	
    foreach ($result as $post) {
	setup_postdata($post);
	$postId = $post->ID;
	$title = $post->post_title;
	$commentCount = $post->comment_count;
		
	if ($commentCount != 0) {
		$strBuidler .= '<li>';
		$strBuidler .= '<a href="' . get_permalink($postId) . '" title="' . $title . '">' . $title . '</a> ';
		$strBuidler .= '(' . $commentCount . ')';
		$strBuidler .= '</li>';
	}
    }	
	
    return $strBuidler;
}
?>

Call the function in your sidebar of footer like this:

<h2><?php _e('Popular Posts'); ?></h2>
<ul>
	<?php echo(listPopularPosts()); ?>
</ul>

Wordpress – Embed Adsense in your posts

Adding Google Adsense to your Blog’s post is easy. First, you have to add the following code to your theme’s functions.php file.

<?php
function showAds() {
    return '<script type="text/javascript"><!--
    google_ad_client = "pub-2102064382433354";
    google_ad_slot = "5772977330";
    google_ad_width = 468;
    google_ad_height = 60;
   //-->
   </script>
   <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
}

add_shortcode('myadsense', 'showAds');
?>

Saved the functions.php file and upload it. Now you can embed an Adsense unit into your posts easily by pasting the following code in the editor, in html mode:

[myadsense]
  • Page 1 of 2
  • 1
  • 2
  • >