Anyone needing to retrieve the base URL path from Magento, just place this one line of code and there you have it! Hope this helps someone.
PHP
1 |
<?php echo Mage::getBaseUrl(); ?> |
Anyone needing to retrieve the base URL path from Magento, just place this one line of code and there you have it! Hope this helps someone.
1 |
<?php echo Mage::getBaseUrl(); ?> |
The popular URL shortening service TinyURL provides a quick API that creates TinyURL’s on the fly. Here’s how you can access that API.
1 2 3 4 5 6 |
<?php function createTinyUrl($strURL) { $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=" . $strURL); return $tinyurl; } ?> |
Make a call to our function above, and it outputs a new tinyURL.
1 |
<?php echo(createTinyUrl('https://www.richardcastera.com/2009/05/09/creating-a-tinyurl-with-tinyurl-api/')); ?> |
Adding Google Adsense to your blog’s post is easy. No need to download and add another plugin to your WordPress installation. Just follow these easy instructions! First, you have to add the following code to your theme’s functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 |
<?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="https://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:
1 |
[myadsense] |
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.
1 |
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> |
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 web page, 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:
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<?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()); ?> |
Here’s a quick function to generate a password. All you have to do is call it passing the length of your required password as an argument.
1 2 3 4 5 6 7 8 9 10 11 12 |
<?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; } ?> |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?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; } } ?> |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<script> function getNameFromPath(strFilepath) { var objRE = new RegExp(/([^\/\\]+)$/); var strName = objRE.exec(strFilepath); if (strName == null) { return null; } else { return strName[0]; } } </script> |
This is a great little function that I whipped up and use to capitalize every word in a string. I can’t tell you how many times I’ve had to use this. Hope you find it useful as I have!
1 2 3 4 5 6 7 8 9 |
<script> function wordToUpper(strSentence) { return strSentence.toLowerCase().replace(/\b[a-z]/g, convertToUpper); function convertToUpper() { return arguments[0].toUpperCase(); } } </script> |
Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.