Richard Castera

Application Developer/Designer
  • Home
  • About
  • Projects

Archive for the ‘Wordpress’ Category

PHP, Web Resources, Wordpress | 1 Comment | March 1, 2010

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;
}
?>
PHP, Wordpress | No Comments | February 25, 2010

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";
PHP, Web Resources, Wordpress | 8 Comments | May 27, 2009

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');
PHP, Web Resources, Wordpress | 9 Comments | May 15, 2009

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>
PHP, Wordpress | 5 Comments | May 8, 2009

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]
PHP, Wordpress | 3 Comments | May 4, 2009

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());
?>
Apache, SEO, Wordpress | No Comments | June 7, 2008

Adding 301 redirects using htaccess

It’s easy adding 301 redirects to your website using Apache’s htaccess. A 301 redirect is the most efficient and Search Engine Friendly method for web page redirection. It’s not difficult to implement and will preserve your search engine rankings as well.

So, basically how this works is when someone tries to access your website without the (www), it will redirect the URL to your website with the www.

To implement this for your website follow these instructions:

  1. Open up notepad or any other text editor and copy and paste the commands below.
  2. Change (yourdomain) to your domain name.
  3. Save the file with this name: (.htaccess). There is no file name.
  4. Upload it to the root directory of your website.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
  • Premium Email Templates

    Social Profiles

  • Twitter
  • Facebook
  • LinkedIn
  • Digg
  • Google
  • GitHub

    Last Tweet

  • Beware the heat-seeking Nerf machine-gun coming to a cubicle near you http://om.ly/svHF #fb
  • Follow me
  • Archives

    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • September 2008
    • August 2008
    • July 2008
    • June 2008
  • Categories

    • AJAX
    • Apache
    • Books
    • Drupal
    • Ecommerce
    • Flash
    • Google
    • Javascript
    • jQuery
    • Magento
    • Marketing
    • Mootools
    • My Thoughts
    • MySQL
    • News
    • Photoshop
    • PHP
    • Prototype
    • SEO
    • Web Resources
    • Wordpress
  • 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

2010 © Copyright. Richard Castera - All Rights Reserved.

Top