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]
WordPress – List the most recent comments
Easily list the most recent comments in a sidebar or a tab. The code below will list the 10 most recent comments. You can change the number displayed by changing the value of the variable, $intCommentLimit to list more or less comments
<?php
function getRecentPosts() {
global $wpdb;
$intCommentLimit = 10;
$strSql = "SELECT DISTINCT ID,
post_title,
post_password,
comment_ID,
comment_post_ID,
comment_author,
comment_date_gmt,
comment_approved,
comment_type,
comment_author_url,
SUBSTRING(comment_content, 1, 50) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $intCommentLimit";
$comments = $wpdb->get_results($strSql);
$strOutput = "<ul>\n";
foreach ($comments as $comment) {
$strOutput .= "<li>" . strip_tags($comment->comment_author) . " Says, <br />" .
"<a href=\"" . get_permalink($comment->ID) . "#comment-" .
$comment->comment_ID . "\" title=\"on " .
$comment->post_title . "\">" .
strip_tags($comment->com_excerpt) . " ...</a></li>\n";
}
$strOutput .= "</ul>\n";
return $strOutput;
}
echo(getRecentPosts());
?>
-
Beware the heat-seeking Nerf machine-gun coming to a cubicle near you http://om.ly/svHF #fb
- Follow me
Last Tweet
-
Archives
Categories
My Favorites
- 37 Signals
- Andrew Warner
- Chris Coyier
- Chris Shiflett
- Collis Ta'eed
- Development Seed
- Drupal
- HubSpot
- James Padolsey
- Joel On Software
- John Resig
- jQuery
- Kevin Rose
- Life Hacker
- Magento
- Mashable
- Matt Cutts
- Matt Ryan
- MySQL
- NetTuts
- Noupe
- Photoshop Tutorials
- PHP
- Smashing Magazine
- Tech Crunch
- WoorkUp
- Wordpress
