WordPress Plugin Skeleton

Here’s a foundation for writing a WordPress plugin, based on version 3.2. This would go in the main my-plugin-name.php file. Continue reading

Posted in Code Snippets | Leave a comment

Escaping shortcodes in WordPress Posts

If you want to display the shortcode literally in a post (like so: [shortcode]), just use double brackets like this: “[[shortcode]]”. You can also use the html entities [ for “[" and ] for "]” (which you’ll need to use if your shortcode doesn’t exist and therefore doesn’t run through the parser).

Posted in Code Snippets | Leave a comment

Setting Up a Virtual Host on WAMP

One of the biggest pains about developing on a local server setup like WAMP is that the root filepaths are different when you go live. To get around this I always set up a virtual host so that my development url can be something like, http://myapplication.localhost/. It’s really easy to set up. Continue reading

Posted in Tutorials | Tagged | Leave a comment

Temporary Tables in Zend Framework

Use temporary tables when your sql queries are starting to do gymnastics. The following would go in your model:

Continue reading

Posted in Tutorials | Leave a comment

Javascript Function Skeleton

(function(){
	var functionName = function(){
			this.init();
		};

	functionName.prototype = {
		init : function() {
	 		this.setFunction();
	 	},	

	 	setFunction : function() {
	 		// do stuff here
	 	}
	};

	new functionName();
})();
Posted in Code Snippets | Tagged | Leave a comment

Focus First Input Field

Here’s a handy little snippet to automatically put the cursor in the first input field on the page. You can override it by adding a class of “nofocus” to any element and/or list the elements in the array. Nice for login pages.


if( !$(':input:visible:enabled:first').hasClass('nofocus') &&
		$.inArray( $(':input:visible:enabled:first').attr('id'),
				  ['element_to_exclude', 'another_element_to_exclude']
		        ) == -1
  ){
	$(':input:visible:enabled:first').focus();
}
Posted in Code Snippets | Tagged | Leave a comment

Generate Excerpt

Here’s a little snippet for generating an excerpt without breaking up a word:

function excerpt($string='', $maxChar=50, $uri='#') {
     $length = strlen($string);
     if ($length < $maxChar) {
          return $string;
     }
     $trimmedString = substr($string, 0, $maxChar);
     $choppedString = substr($trimmedString, 0, strrpos($trimmedString, strrchr($trimmedString, ' ')));
     $newString = $choppedString . ' <a href="' . $uri . '">more</a>';
     return $newString;
}
Posted in Code Snippets | Tagged | Leave a comment