Richard Castera

Application Developer/Designer
  • Home
  • About
  • Projects
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]
Web Resources | No Comments | May 7, 2009

Make IE8 Emulate IE7

By now you should know about the official release of Internet Explorer 8. This is a huge milestone for the browser that most Web Developers have come to hate.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
Javascript, Mootools | 2 Comments | May 6, 2009

MooTools – Free Syntax Highlighting Class

mootools-syntax-highlighter

Lighter.js is a free syntax highlighting class developed with MooTools. It was created with the MooTools developer in mind and takes advantage of many of the Framework’s features. Using it can be as simple as adding a single script to your webpage, selecting the elements you wish to highlight, and Lighter.js takes care of the rest.

All browsers supported by MooTools are compatible with Lighter.js. It’s possible that it may work with earlier/other browsers but these are unofficially supported. The official list is:

  • Safari 2+
  • Internet Explorer 6+
  • Firefox 2+
  • Opera 9+
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());
?>
PHP | No Comments | September 16, 2008

PHP – Generate a random password based on length

<?php
function generatePassword($intNumOfChars) {
    if (is_numeric($intNumOfChars) && ($intNumOfChars > 0)) {
	$strChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	for ($i = 0; $i < $intNumOfChars; $i ++)  {
	    $strPassword .= $strChars[rand(0, strlen($strChars)-1)];
	 }
    }
    return $strPassword;
}
?>
PHP | No Comments | September 10, 2008

PHP – Truncate a string to a given length

This is a function I use to display the ellipses when I want to truncate and display a summary of a larger body of text.

<?php
function truncateString($intLength = 0, $strText = "") {
    if ($intLength == 0) {
        return $strText;
    }
    if(strlen($strText) > $intLength) {
        preg_match("/[a-zA-Z0-9]{0, " . $intLength . "}/", $strText, $strNewText);
        return ($strNewText . "...");
    }
    else {
        return $strText;
    }
}
?>
Javascript | 5 Comments | August 9, 2008

Get the filename from upload form using Javascript

I needed a way to access the filename of a file being uploaded or attached using the input file from a form. So, I created a nice little function to achieve this. Hopefully it comes in handy for someone.

<script type="text/javascript">
function getNameFromPath(strFilepath) {
    var objRE = new RegExp(/([^\/\\]+)$/);
    var strName = objRE.exec(strFilepath);
    if (strName == null) {
        return null;
    }
    else {
        return strName[0];
    }
}
</script>
  • Page 10 of 14
  • <
  • 1
  • ...
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • >
  • Premium Email Templates

    Social Profiles

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

    Last Tweet

  • J. K. Rowling donates $15 million for MS clinic http://om.ly/tkkw
  • 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