<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>CatsWhoCode.com</title>
	
	<link>http://www.catswhocode.com/blog</link>
	<description>Web Development Blog</description>
	<lastBuildDate>Wed, 23 May 2012 09:29:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Catswhocode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="catswhocode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">Catswhocode</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Tips and best practices to develop responsive websites</title>
		<link>http://www.catswhocode.com/blog/tips-and-best-practices-to-develop-responsible-websites</link>
		<comments>http://www.catswhocode.com/blog/tips-and-best-practices-to-develop-responsible-websites#comments</comments>
		<pubDate>Mon, 14 May 2012 14:42:35 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4932</guid>
		<description><![CDATA[In the recent years, we saw both a rise of mobile devices such as the iPhone and wide monitors. Responsive websites are website that can adapt to lots of different screen resolution and always look good. In this article, I have compiled tips and best practices to create responsive websites.]]></description>
			<content:encoded><![CDATA[<h2>Start with a template</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/1140grid1.png" alt="" /><br />
Sure, you can start coding from scratch, but there&#8217;s a lot of interesting free templates that will make you save a lot of time. Among others, I recommend <a href="http://html5boilerplate.com/mobile">Mobile boilerplate</a>, <a href="http://cssgrid.net/">The 1140 grid</a> and <a href="http://www.getskeleton.com/">Skeleton</a>. There&#8217;s a lot more than those ones, so feel free to google &#8220;responsive web design template&#8221; if you want more.</p>
<h2>Working with fluid grid based layouts</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/grid.png" alt="" /><br />
Fluid layouts are an important part of a good responsive layout. In order to have a website that can adapt to many different screen resolutions, you have to use a fluid layout with widths defined in percents instead of pixels.</p>
<p>To get the size in percents from a size in pixels, you have to take the element&#8217;s width and divide it by the full grid size. For example: 200 px (element size) / 960 px (grid size) = 0.2083. Multiply this by 100, and you&#8217;ll get 20,83%.</p>
<p>This is why it is interesting to work with a 1000px grid. 1000 is a round number, and it is easy to calculate that 24% of this size will be equal to 240 pixels. For more info about 1000px grids, I recommend you to check out <a href="http://elliotjaystocks.com/blog/a-better-photoshop-grid-for-responsive-web-design/">this article</a>.</p>
<h2>Flexible images</h2>
<p>A very important aspect of a responsive layout is how images can adapt to the size of their parent container. The basic solution is to define a maximum width of 100%. This will make sure that your images are never wider than the parent container.</p>
<pre>
.content img{
   max-width:100%;
}
</pre>
<p>A better solution is to use context-aware image sizing. This technique basically consists of having different sizes of an image, and displaying only the size adapted to the device. Quick example:</p>
<pre>
&lt;img src=&quot;image.jpg&quot; data-src-600px=&quot;image-600px.jpg&quot; data-src-800px=&quot;image-800px.jpg&quot; alt=&quot;&quot;&gt;
</pre>
<p>And the related CSS:</p>
<pre>
@media (min-device-width:600px) {
    img[data-src-600px] {
        content: attr(data-src-600px, url);
    }
}

@media (min-device-width:800px) {
    img[data-src-800px] {
        content: attr(data-src-800px, url);
    }
}
</pre>
<p>For more info about this technique, check out this <a href="http://nicolasgallagher.com/responsive-images-using-css3/">article</a>.</p>
<h2>jQuery is your friend</h2>
<p>jQuery is definitely a super useful tool when it comes to web development. Lots of jQuery plugins can help you to create better responsive websites.<br />
A quick round up of my personal favorites:</p>
<ul>
<li><a href="http://fittextjs.com/">FitText</a>: A plugin that makes font-sizes flexible.</li>
<li><a href="http://tympanus.net/codrops/2011/09/12/elastislide-responsive-carousel/">Elastislide</a>: A responsive jQuery carousel plugin.</li>
<li><a href="http://buildinternet.com/project/supersized/">Supersized</a>: A fullscreen background slideshow plugin.</li>
<li><a href="http://fitvidsjs.com/">FitVids</a>: A lightweight, easy-to-use jQuery plugin for fluid width video embeds.</li>
</ul>
<h2>Don&#8217;t forget Apple&#8217;s viewport</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/viewport1.jpg" alt="" /></p>
<p>The <code>&lt;meta name="viewport""&gt;</code> tag was introduced by Apple for their mobile devices (iPhones, iPads and iPods Touch). This tag allow you to specify the default size of a page when viewed with an iPhone or iPad.</p>
<pre>
&lt;meta name="viewport" content="width=device-width; initial-scale=1.0"&gt;
</pre>
<p>The code above will ensure that upon opening, your layout will be displayed properly at 1:1 scale. No zooming will be applied.</p>
<p>For more info, feel free to check out <a href="http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safarihtmlref/Articles/MetaTags.html">Apple developper documentation</a>.</p>
<h2>Scalable background images</h2>
<p>The CSS3 specification introduced a new attribute named <code>background-size</code>. As you probably guessed, it is used to define the size of background images. It can be a size in pixels, or it can use some of the reserved keywords. The <code>cover</code> keyword scale the background image (while preserving original proportions) to be as large as possible so that the background positioning area is completely covered by the background image.</p>
<pre>
html {
	background: url(bg.jpg) no-repeat center center fixed;
	-webkit-background-size: cover;
	-moz-background-size: cover;
	-o-background-size: cover;
	background-size: cover;
}
</pre>
<p>The solution above works perfectly in Chrome, Safari 3+, IE 9+, Firefox 3.6+ and Opera 10+. If you&#8217;re looking for a solution that works in older browsers, I highly suggest using this <a href="http://nooshu.com/jquery-plug-in-scalable-background-image">jQuery plugin</a> or one of the alternative CSS tweaks published <a href="http://css-tricks.com/perfect-full-page-background-image/">here</a>.</p>
<h2>Get inspired</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/mediaqueries.png" alt="" /><br />
When designing a website, it is always good to be able to get inspired by what others have done. Since the rise of responsive web design, online galleries have been created to showcase the best responsive websites.</p>
<p>The most complete gallery is definitely <a href="http://www.mediaqueri.es">mediaqueri.es</a>, but if you need some more inspiration, you can get it <a href="http://www.responsivewebdesign.co.uk/gallery/">here</a> or <a href="http://www.webdesignerdepot.com/2011/09/the-ultimate-responsive-web-design-roundup/">here</a>. </p>
<h2>Test, test, test, and test again!</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/screenqueries.png" alt="" /><br />
Indeed, when developing a responsive layout, you have to test it in different resolutions. Of course, you can manually resize your browser, but why not using one of the useful tools created to simplify this task?</p>
<p>Lots of differents tools are available for you to test your website in different screen sizes. At the moment, my favorites are definitely <a href="http://screenqueri.es/">ScreenQueri.es</a> and <a href="http://resizemybrowser.com/">Resize my browser</a>.</p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/mobozlo5hO0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/tips-and-best-practices-to-develop-responsible-websites/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Super useful online tools to work with images</title>
		<link>http://www.catswhocode.com/blog/super-useful-online-tools-to-work-with-images</link>
		<comments>http://www.catswhocode.com/blog/super-useful-online-tools-to-work-with-images#comments</comments>
		<pubDate>Mon, 07 May 2012 14:13:41 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4909</guid>
		<description><![CDATA[Images are indeed a big part of a website, and as a developer or designer you often have to work with them. Sure, there's desktop applications like Photoshop or Gimp, but there's also a bunch of super useful online tools to store, resize, and modify images online. Here's a round up of the best tools available. ]]></description>
			<content:encoded><![CDATA[<h2>Minus</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/minus.png" alt="" /><br />
As a developer or designer, you often need to upload images for sharing them with clients or people you work with. Many websites allow you to do so, but what I really love with Minus is how quick and easy it is: Just drop your image on their website, and it&#8217;s online. They&#8217;ll even give you a short url so you can share your image easily. No registration required!</p>
<p>Just one request, I hope they&#8217;ll add a resize image feature soon.<br />
<strong>&rarr; Visit <a href="http://www.minus.com">Minus</a></strong></p>
<h2>Smush It</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/smushit.png" alt="" /><br />
When using images on the web, one thing you must definitely think about is the image size. You need to find the good balance between image weight and quality. Smush It is a tool developed by Yahoo! which allow you to optimize your images without losing quality. WordPress users, note that there&#8217;s a WP plugin available.<br />
<strong>&rarr; Visit <a href="http://www.smushit.com/ysmush.it/">Smush It</a></strong></p>
<h2>Placehold It</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/placehold.png" alt="" /><br />
When creating a website layout, you often need placeholder images of an exact size. Placehold It allows you to dynamically create placeholder images. To use it in your designs, simply use urls like this: <code>&lt;img src="http://placehold.it/350x150"&gt;</code> to display a 350*150 pixels placeholder image.<br />
<strong>&rarr; Visit <a href="http://www.placehold.it">Placehold It</a></strong></p>
<h2>Resize images online</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/resize.png" alt="" /><br />
Don&#8217;t want to open Photoshop just for resizing an image? This site is here to help. Just upload your image, specify the desired size, and you&#8217;re ready to go!<br />
<strong>&rarr; Visit <a href="http://www.softorbits.com/resize-images-online/">Resize images online</a></strong></p>
<h2>Photoshop online tools</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/photoshop.png" alt="" /><br />
When it comes to image editing, Adobe Photoshop is definitely the most popular software. Adobe launched a light version of Photoshop which is available online. The online app is quite powerful and has many features. Unfortunely you have to register to use Photoshop online.<br />
<strong>&rarr; Visit <a href="http://www.photoshop.com/tools">Photoshop online tools</a></strong></p>
<h2>Pixlr express</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/pixelr.png" alt="" /><br />
Pixlr express is a simple but powerful app which allow you to resize images, add effects, borders, watermarks, etc. The app is free and does not require registration.<br />
<strong>&rarr; Visit <a href="http://pixlr.com/express/">Pixelr express</a></strong></p>
<h2>Aviary Phoenix</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/05/aviary.png" alt="" /><br />
Developed in Flash, Aviary Phoenix is a super-complete and free online image editor. A real &#8220;light photoshop&#8221; that you can access from any computer, without any registration.<br />
<strong>&rarr; Visit <a href="http://advanced.aviary.com/tools/image-editor">Aviary Phoenix</a></strong></p>
<p><strong><em>I just created a <a href="http://www.facebook.com/catswhocode">Facebook page for Cats Who Code</a>, so don&#8217;t hesitate to become a fan!</em></strong></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/fLu7joVrU3s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/super-useful-online-tools-to-work-with-images/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Super useful WordPress action hooks and filters</title>
		<link>http://www.catswhocode.com/blog/super-useful-wordpress-action-hooks-and-filters</link>
		<comments>http://www.catswhocode.com/blog/super-useful-wordpress-action-hooks-and-filters#comments</comments>
		<pubDate>Mon, 23 Apr 2012 14:04:38 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4889</guid>
		<description><![CDATA[Action hooks and filters are very useful in WordPress. They allow you to "hook" a custom function to an existing function, which allows you to modify WordPress functionality without editing core files. Today, here are 10 super usefull action hooks and filters to supercharge your WordPress install!]]></description>
			<content:encoded><![CDATA[<h2>Prevent automatic image compression</h2>
<p>By default, WordPress compress jpg images when you upload them to your blog. This is useful because it saves bandwidth and loading time, but sometimes you may prefer to have full quality images (For example, if you&#8217;re a photographer using WordPress to showcase your work).</p>
<p>Paste the code below into your <code>functions.php</code> file to remove automatic compression of images.</p>
<pre>
add_filter('jpeg_quality', function($arg){return 100;});
</pre>
<p><strong>&rarr; Source: <a href="http://www.wprecipes.com/prevent-wordpress-to-compress-your-jpg-images">http://www.wprecipes.com/prevent-wordpress-to-compress-your-jpg-images</a></strong></p>
<h2>Add target=&#8221;blank&#8221; to all links</h2>
<p>I&#8217;ve never been a fan of <code>target="blank"</code> links, but I&#8217;m always surprised to see how clients love them. So if you need to transform all links to <code>target="blank"</code> links, here is an easy solution. </p>
<p>This function have to be pasted in your <code>functions.php</code> file.</p>
<pre>function autoblank($text) {
	$return = str_replace('&lt;a', '&lt;a target=&quot;_blank&quot;', $text);
	return $return;
}
add_filter('the_content', 'autoblank');</pre>
<p><strong>&rarr; Source: <a href="http://www.catswhocode.com/blog/snippets/add-target_blank-on-all-link">http://www.catswhocode.com/blog/snippets/add-target_blank-on-all-link</a></strong></p>
<h2>Add extra contact methods to user profiles</h2>
<p>By default, WordPress allow users to enter an AIM name on their profile, but no Facebook and no Twitter names! But in 2012, those websites are far more popular than the good old AIM (ah, memories&#8230;).</p>
<p>In order to add more contact methods to user profile, simply paste this hook in your <code>functions.php</code> file. In this example it will add Facebook and Twitter, but it can be used for any website or service you need.</p>
<pre>
function my_user_contactmethods($user_contactmethods){
  $user_contactmethods['twitter'] = 'Twitter Username';
  $user_contactmethods['facebook'] = 'Facebook Username';

  return $user_contactmethods;
}

add_filter('user_contactmethods', 'my_user_contactmethods');
</pre>
<p><strong>&rarr; Source: <a href="http://wp.tutsplus.com/tutorials/quick-tip-add-extra-contact-methods-to-user-profiles/">http://wp.tutsplus.com/tutorials/quick-tip-add-extra-contact-methods-to-user-profiles/</a></strong></p>
<h2>Remove the &#8220;read more&#8221; jump</h2>
<p>On WordPress blogs, when you click on a &#8220;Read more&#8221; link, it automatically drops to the point in the article you theoretically just got to the end of. If you don&#8217;t really like that jump, simply paste the following code into your <code>functions.php</code> file to get rid of it.</p>
<pre>
function wdc_no_more_jumping($post) {
     return &#39;&lt;a href=&quot;&#39;.get_permalink($post-&gt;ID).&#39;&quot; class=&quot;read-more&quot;&gt;&#39;.&#39;Continue Reading&#39;.&#39;&lt;/a&gt;&#39;;
}
add_filter(&#39;excerpt_more&#39;, &#39;wdc_no_more_jumping&#39;);
</pre>
<p><strong>&rarr; Source: <a href="http://wpshout.com/wordpress-functions-php/">http://wpshout.com/wordpress-functions-php/</a></strong></p>
<h2>Automatically enable threaded comments</h2>
<p>By default, WordPress do not enable threaded comments. If you want/need to change this, here is a handy code snippet to paste in your <code>functions.php</code> file:</p>
<pre>
function enable_threaded_comments(){
 if (!is_admin()) {
  if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
   wp_enqueue_script('comment-reply');
  }
}

add_action('get_header', 'enable_threaded_comments');
</pre>
<p><strong>&rarr; Source: <a href="http://wpshout.com/wordpress-functions-php/">http://wpshout.com/wordpress-functions-php/</a></strong></p>
<h2>How to show an urgent message in the WordPress admin area</h2>
<p>When writing custom WordPress theme or plugins, you might want to inform users that something important needs doing, perhaps due to an upgrade. e.g. You need the user to update a setting, or check that their settings have been transposed correctly. Here is a ready to use hook to display a custom message to admins.</p>
<pre>
function showMessage($message, $errormsg = false){
	if ($errormsg) {
		echo &#39;&lt;div id=&quot;message&quot; class=&quot;error&quot;&gt;&#39;;
	} else {
		echo &#39;&lt;div id=&quot;message&quot; class=&quot;updated fade&quot;&gt;&#39;;
	}

	echo &quot;&lt;p&gt;&lt;strong&gt;$message&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&quot;;
}  

function showAdminMessages() {
    showMessage(&quot;You need to upgrade your database as soon as possible...&quot;, true);

    if (user_can(&#39;manage_options&#39;) {
       showMessage(&quot;Hello admins!&quot;);
    }
}

add_action(&#39;admin_notices&#39;, &#39;showAdminMessages&#39;);
</pre>
<p><strong>&rarr; Source: <a href="http://www.wpdoctors.co.uk">http://www.wpdoctors.co.uk</a></strong></p>
<h2>Automatically replace words in your posts</h2>
<p>Imagine this: your blog was named &#8220;myblog&#8221; and for some reason you renamed it &#8220;mysuperblog&#8221;. Don&#8217;t edit your XXX posts to replace every single occurence! Instead, paste this useful hook into your <code>functions.php</code> file and let it do the work for you.</p>
<pre>
function replace_text_wps($text){
    $replace = array(
        // 'WORD TO REPLACE' =&gt; 'REPLACE WORD WITH THIS'
        'wordpress' =&gt; '&lt;a href=&quot;#&quot;&gt;wordpress&lt;/a&gt;',
        'excerpt' =&gt; '&lt;a href=&quot;#&quot;&gt;excerpt&lt;/a&gt;',
        'function' =&gt; '&lt;a href=&quot;#&quot;&gt;function&lt;/a&gt;'
    );
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;
}

add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');
</pre>
<p><strong>&rarr; Source: <a href="http://wpsnipp.com/">http://wpsnipp.com/</a></strong></p>
<h2>Add post thumbnails to RSS feed</h2>
<p>This very cool piece of code will get the post thumbnail and automatically add it to your RSS feeds. Paste the code into <code>functions.php</code> and save the file. Don&#8217;t forget that you need to use a theme that supports <a href="http://codex.wordpress.org/Post_Thumbnails">post thumbnails</a> for this snippet to work.</p>
<pre>
function cwc_rss_post_thumbnail($content) {
    global $post;
    if(has_post_thumbnail($post-&gt;ID)) {
        $content = &#39;&lt;p&gt;&#39; . get_the_post_thumbnail($post-&gt;ID) .
        &#39;&lt;/p&gt;&#39; . get_the_content();
    }

    return $content;
}
add_filter(&#39;the_excerpt_rss&#39;, &#39;cwc_rss_post_thumbnail&#39;);
add_filter(&#39;the_content_feed&#39;, &#39;cwc_rss_post_thumbnail&#39;);
</pre>
<p><strong>&rarr; Source: <a href="http://snipplr.com/view.php?codeview&#038;id=56180">http://snipplr.com/view.php?codeview&#038;id=56180</a></strong></p>
<h2>Quick maintenance mode</h2>
<p>Sometimes, you need to put your blog on hold while performing some maintenance. Many plugins are allowing you to do so, but here is a simpler solution: Just paste the following snippet into your functions.php file and save it. Your blog is now unavailable to anyone except administrators. Don’t forget to remove the code when you’re done with maintenance!</p>
<pre>
function cwc_maintenance_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        wp_die('Maintenance, please come back soon.');
    }
}
add_action('get_header', 'cwc_maintenance_mode');
</pre>
<p><strong>&rarr; Source: <a href="http://skyje.com/2011/05/wordpress-code-snippets/">http://skyje.com/2011/05/wordpress-code-snippets/</a></strong></p>
<h2>Remove comments autolinks</h2>
<p>If someone leaves a comment containing a url on your WordPress blog, the url will be automatically transformed to a link by WordPress. This can be useful, but personally I don’t like to see many links in comments, especially when they’re a bit spammy.<br />
Removing autolinks is pretty easy: Just paste the following code into your <code>functions.php file</code>: Once you saved the file, you’ll notice that autolinks have disappeared.</p>
<pre>
remove_filter('comment_text', 'make_clickable', 9);
</pre>
<p><strong>&rarr; Source: <a href="http://www.wprecipes.com/wordpress-hack-remove-autolinks-in-comments">http://www.wprecipes.com/wordpress-hack-remove-autolinks-in-comments</a></strong></p>
<p><em>By the way, I just created a <a href="http://www.facebook.com/pages/Cats-Who-Code/302807633129400">Facebook page for Cats Who Code</a>, some feel free to &#8220;like&#8221; the blog!</em></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/omuCfhfJTHw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/super-useful-wordpress-action-hooks-and-filters/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Awesome sites to find useful code snippets</title>
		<link>http://www.catswhocode.com/blog/awesome-sites-to-find-useful-code-snippets</link>
		<comments>http://www.catswhocode.com/blog/awesome-sites-to-find-useful-code-snippets#comments</comments>
		<pubDate>Tue, 10 Apr 2012 14:54:21 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4851</guid>
		<description><![CDATA[As a developer, I really like to collect and keep a library of useful code snippets that allow me to save a lot of time when building websites or apps. Today, I have compiled a list of the most interesting websites to find useful code snippets. ]]></description>
			<content:encoded><![CDATA[<h2>CatsWhoCode snippet library</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/cwc-snippets.png" alt="" /><br />
Some of you already know it, but a few weeks ago I&#8217;ve created a snippet library with a picky selection of usefull snippets focused on web development: PHP, JavaScript, CSS, htaccess&#8230; Approximately one new snippet is published every day. Users are welcome to submit their own snippets.<br />
<strong>&rarr; Visit <a href="http://www.catswhocode.com/blog/snippets">CatsWhoCode snippet library</a></strong></p>
<h2>Snipplr</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/snipplr.png" alt="" /><br />
Snipplr is probably the largest code snippet repository available on the internet. Since 5 years, they have published thousand of pieces of code. Some snippets are super useful, some other not so, but there&#8217;s a strong chance that you&#8217;ll find what you need on a website with so many snippets.<br />
<strong>&rarr; Visit <a href="http://snipplr.com/">Snipplr</a></strong></p>
<h2>WPRecipes</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/wprecipes.png" alt="" /><br />
Another site of mine, where I publish only WordPress related snippets since 2009. More than 300 snippets are available, so don&#8217;t miss it if you work with WordPress!<br />
<strong>&rarr; Visit <a href="http://www.wprecipes.com">WPRecipes</a></strong></p>
<h2>PHP Snips</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/phpsnips.png" alt="" /><br />
Are you into PHP? If yes, you&#8217;ll for sure love PHP Snips, a PHP-only code snippets library. Hundreds of snippets are freely available, most of them are very useful and well coded.<br />
<strong>&rarr; Visit <a href="http://phpsnips.com/">PHP Snips</a></strong></p>
<h2>DZone code snippets</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/dzone.png" alt="" /><br />
DZone Snippets is a public source code repository, hosted by popular developer website DZone. Thousands of snippets in more than 25 languages are available. As it is 100% user powered, quality is very mixed: some snippets are useful and well coded while some other are a complete waste of time.<br />
<strong>&rarr; Visit <a href="http://snippets.dzone.com/">DZone code snippets</a></strong></p>
<h2>Jonas John snippet library</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/jonasjohn.png" alt="" /><br />
Currently 143 quality code snippets, covering PHP, C#, Visual Basic, JavaScript, and more. A good resource to keep in your bookmarks!<br />
<strong>&rarr; Visit <a href="http://www.jonasjohn.de/snippets/">Jonas John snippet library</a></strong></p>
<h2>Code Beach</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/codebeach.png" alt="" /><br />
Code Beach is a central repository where Mac developers can share pieces of useful code in all programming languages used on Mac: Objective C, Ruby, C, C++, Python&#8230; Don&#8217;t miss it if you&#8217;re a Mac developper!<br />
<strong>&rarr; Visit <a href="http://codebeach.org/">Code Beach</a></strong></p>
<h2>CodeKeep</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/codekeep.png" alt="" /><br />
With more than 18,000 code snippets, there&#8217;s a strong change that you&#8217;ll find what you need on CodeKeep. The site have compiled snippets in various languages such as C#, C++, ActionScript, ASP, VB and more.<br />
<strong>&rarr; Visit <a href="http://codekeep.net/">CodeKeep</a></strong></p>
<h2>Code Codex</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/04/codecodex.png" alt="" /><br />
Using the poipular <em>wiki</em> formula, Code Codex is a website where you can find and add lots of snippets in languages like C, C++, Java, Perl, and more.<br />
<strong>&rarr; Visit <a href="http://www.codecodex.com/wiki/Main_Page">Code Codex</a></strong></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/zd5jHuQl2Mg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/awesome-sites-to-find-useful-code-snippets/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Sending SMS with PHP and TextMagic: An A to Z guide</title>
		<link>http://www.catswhocode.com/blog/sending-sms-with-php-and-textmagic-an-a-to-z-guide</link>
		<comments>http://www.catswhocode.com/blog/sending-sms-with-php-and-textmagic-an-a-to-z-guide#comments</comments>
		<pubDate>Mon, 26 Mar 2012 13:57:56 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4834</guid>
		<description><![CDATA[Over the years, Short message service (SMS) has become a very important way of communication, and many businesses are looking for easy ways to send automated text messages to their customers. In this tutorial, I'm going to show you how you can send SMS using PHP and a third party service called <a href="http://is.gd/textmagic">TextMagic</a>. Its very easy to do!]]></description>
			<content:encoded><![CDATA[<h2>Step 1: Creating a TextMagic account</h2>
<p>In order to send SMS to mobile phones, you need to use a third-party service. In this tutorial, I&#8217;m using a service called <a href="http://is.gd/textmagic">TextMagic</a> to send SMS. There are lots of other services to do so, but I&#8217;ve tested Textmagic and I&#8217;m very happy with it so far. </p>
<p>To use TextMagic, you have to create an account. Go <a href="http://is.gd/textmagic">here</a> and register. Prices starts at $27 for 200 SMS (13.5 cents per sms)</p>
<h2>Step 2: Configure your API account</h2>
<p>Once you have created your TextMagic account, go to My services &rarr; API &rarr; Password. You need to generate an API password in order to be able to send SMS from your website. Just enter your account password and click on &#8220;Generate API password&#8221;. </p>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/03/textmagic.png" alt="" /></p>
<p>Once done, you have to download the API files. Go to <a href="http://api.textmagic.com/https-api/sms-api-php-wrapper">this page</a> and click on the &#8220;Download&#8221; button to get the API files. Extract the <code>textmagic-sms-api-php.zip</code> file and upload all of its content to your server.</p>
<h2>Step 3: Let&#8217;s code!</h2>
<p>Now, we have to create a function that will send the SMS throught the TextMagic API. The following code, taken from TextMagic website is the easiest way to send a SMS using the TextMagic API.</p>
<pre>
require('textmagic-sms-api-php/TextMagicAPI.php');

$api = new TextMagicAPI(array(
    "username" => "yourTextMeUsername",
    "password" => "yourTextMePassword"
));

$text = "Your message here";

// Use this number for testing purposes. This is absolutely free.
$phones = array(9991234567);

$results = $api->send($text, $phones, true);
</pre>
<p>So how does this code works? First, I&#8217;m including the TextMagic API. Then we have to instantiate a <code>TextMagicAPI</code> object. To do so, you need your TextMagic username as well as your API password. <code>$phones</code> is an array that can contains how many phone numbers as you want. Useful for bulk text messaging! </p>
<p>Finally, the SMS is sent using the <code>sent</code> method. For testing purposes, you can use the <code>9991234567</code> number provided by TextMagic. It is totally free!</p>
<p>Now, how to make sure your SMS has been sent? Easy, just see if <code>$results</code> is true:</p>
<pre>
if ($results = $api->send($text, $phones, true)){
    echo &quot;SMS sent successfully!&quot;;
}
</pre>
<p>You&#8217;re done. This is basically all you need to send text messages with <a href="http://is.gd/textmagic">TextMagic</a>.<br />
By the way, if anyone ever heard of a free and reliable service to send SMS, please let me know in a comment!</p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/1k9MtulU0dY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/sending-sms-with-php-and-textmagic-an-a-to-z-guide/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>10+ useful SQL queries to clean up your WordPress database</title>
		<link>http://www.catswhocode.com/blog/10-useful-sql-queries-to-clean-up-your-wordpress-database</link>
		<comments>http://www.catswhocode.com/blog/10-useful-sql-queries-to-clean-up-your-wordpress-database#comments</comments>
		<pubDate>Mon, 12 Mar 2012 14:59:03 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4814</guid>
		<description><![CDATA[After years of usage, your WordPress database can contain weird characters, be filled with data you don't need anymore, and so on. In this article, I'm going to show you 10+ SQL queries to clean up your WordPress database.]]></description>
			<content:encoded><![CDATA[<p><strong>Two things to note:</strong> First, any of these queries should be preceded by a backup of your whole database. Secondly, don&#8217;t forget to replace the <code>wp_</code> table prefix by the prefix used on your WordPress install, otherwise the queries won&#8217;t work.</p>
<h2>Clean up your WordPress database from weird characters</h2>
<p>Encoding problems can be really painful. Instead of manually update all of your posts, here is a query that you can run in order to clean your database from weird characters.</p>
<pre>
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€œ', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€™', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€˜', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€”', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€“', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€¢', '-');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€¦', '…');

UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€œ', '“');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€', '”');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€™', '’');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€˜', '‘');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€”', '–');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€“', '—');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€¢', '-');
UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€¦', '…');
</pre>
<p><strong>&rarr; Source: <a href="http://digwp.com/2011/07/clean-up-weird-characters-in-database">http://digwp.com/2011/07/clean-up-weird-characters-in-database</a></strong></p>
<h2>Close trackbacks on all posts at once</h2>
<p>Do you use trackbacks and pings? Many people seems to find them useless. In order to get rid of them, you can close trackbacks post by post, but this will consume a lot of time. Or, of course,  you can use a good old SQL query, as shown below:</p>
<pre>
UPDATE wp_posts SET ping_status = 'closed';
</pre>
<p><strong>&rarr; Source: <a href="http://www.wprecipes.com/wordpress-tip-close-trackbacks-on-all-posts-at-once">http://www.wprecipes.com/wordpress-tip-close-trackbacks-on-all-posts-at-once</a></strong></p>
<h2>Get rid of all unused shortcodes</h2>
<p>I love WordPress shortcodes, but there&#8217;s a problem with them: Once you stop using a shortcode (for example when you switch to another theme) you&#8217;ll find shortcodes in full text on your posts. Here&#8217;s a SQL query to remove them. Just update the code with the shortcode you want to remove. I&#8217;ve used <code>[tweet]</code> in this example.</p>
<pre>
UPDATE wp_post SET post_content = replace(post_content, '[tweet]', '' ) ;
</pre>
<p><strong>&rarr; Source: <a href="http://www.wprecipes.com/wordpress-tip-get-rid-of-unused-shortcodes">http://www.wprecipes.com/wordpress-tip-get-rid-of-unused-shortcodes</a></strong></p>
<h2>Delete specific post meta</h2>
<p>If you used to add a specific custom field to your posts but do not need it anymore, you can remove the undesired meta quickly with this query. </p>
<pre>
DELETE FROM wp_postmeta WHERE meta_key = 'YourMetaKey';
</pre>
<p><strong>&rarr; Source: <a href="http://www.esoftload.info/10-sql-statements-for-wordpress">http://www.esoftload.info/10-sql-statements-for-wordpress</a></strong></p>
<h2>Delete all unused post tags</h2>
<p>Remember 4 or 5 years ago, tags where very popular in blogging. But now, many bloggers stopped used them. If you did, save some space on your database by cleaning it from unused tags.</p>
<pre>
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );
DELETE FROM wp_term_taxonomy WHERE term_id not IN (SELECT term_id FROM wp_terms);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
</pre>
<p><strong>&rarr; Source: <a href="http://4rapiddev.com/tips-and-tricks/wordpress-delete-unused-post-tags-by-sql-command/">http://4rapiddev.com/tips-and-tricks/wordpress-delete&#8230;</a></strong></p>
<h2>Delete feed cache</h2>
<p>WordPress stores the feed cache in the <code>wp_options</code> table. If you want to flush the feed cache, you can do so by using the following query:</p>
<pre>
DELETE FROM `wp_options` WHERE `option_name` LIKE ('_transient%_feed_%')
</pre>
<p><strong>&rarr; Source: <a href="http://wpengineer.com/2114/delete-all-feed-cache-via-sql-in-wordpress/">http://wpengineer.com/2114/delete-all-feed-cache&#8230;</a></strong></p>
<h2>Delete all post revisions and their metadata</h2>
<p>Post revisions is an useful feature, but if you don&#8217;t delete the many revisions from time to time your database will quickly become very big. The following query deletes all post revisions as well as all the metadata associated with the revisions.</p>
<pre>
DELETE a,b,c FROM wp_posts a WHERE a.post_type = 'revision' LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);
</pre>
<p><strong>&rarr; Source: <a href="http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/">http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries&#8230;</a></strong></p>
<h2>Batch delete old posts</h2>
<p>Don&#8217;t need those posts published years ago? Delete them using this query. This example is set to delete any post which is older than 600 days. If you want to make an even better version of this query, what about mixing it with the one below to remove old posts as well as their metadata?</p>
<pre>
DELETE FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 600
</pre>
<p><strong>&rarr; Source: <a href="http://stackoverflow.com/questions/5317599/wordpress-automatically-delete-posts-that-are-x-days-old">http://stackoverflow.com/questions/5317599/wordpress-automatically-delete-posts&#8230;</a></strong></p>
<h2>Remove comment agent</h2>
<p>By default, when someone comments on your blog, WordPress saves the user agent in the database. It can be useful for stats, but for 95% of bloggers it is just useless. This query will replace the user agent with a blank string, which can reduce your database size if you have lots of comments.</p>
<pre>
update wp_comments set comment_agent ='' ;
</pre>
<p><strong>&rarr; Source: <a href="http://www.rsatechnologies.in/best-sql-queries-for-wordpress-administrator.html">http://www.rsatechnologies.in/best-sql-queries-for&#8230;</a></strong></p>
<h2>Batch disable all plugins</h2>
<p>Sometimes, for exemple when you have to upgrade your blog, you need to disable all your plugins. Depending to how much plugins you’re using, it can takes a lot of time and be kinda boring. Here is an useful SQL query to disable all your plugins at once!</p>
<pre>
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';
</pre>
<p><strong>&rarr; Source: <a href="http://www.wprecipes.com/how-to-disable-all-your-plugins-in-a-second">http://www.wprecipes.com/how-to-disable-all-your-plugins&#8230;</a></strong></p>
<h2>Change author attribution on all posts at once</h2>
<p>Do you need to change author attribution on many posts? If yes, you don&#8217;t have to do it manually. Here&#8217;s a handy query to do the job for you.</p>
<p>The first thing to do is getting the IDs of WordPress users. Once logged in phpmyadmin, insert the following SQL command:</p>
<pre>SELECT ID, display_name FROM wp_users;</pre>
<p>Right now, phpmyadmin displayed a list of WordPress users associated with their IDs. Let&#8217;s say that NEW_AUTHOR_ID is the ID of the &#8220;new&#8221; author, and OLD_AUTHOR_ID is the old author ID.</p>
<pre>UPDATE wp_posts SET post_author=NEW_AUTHOR_ID WHERE post_author=OLD_AUTHOR_ID;</pre>
<p>That&#8217;s all. Once this last command has been run, all posts from the old author now appears to have been written by the new author.<br />
<strong>&rarr; Source: <a href="http://www.wprecipes.com/how-to-change-author-attribution-on-all-posts-at-once">http://www.wprecipes.com/how-to-change-author-attribution&#8230;</a></strong></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/OAt20r9LXDg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/10-useful-sql-queries-to-clean-up-your-wordpress-database/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>10 awesome HTML5 audio players</title>
		<link>http://www.catswhocode.com/blog/10-awesome-html5-audio-players</link>
		<comments>http://www.catswhocode.com/blog/10-awesome-html5-audio-players#comments</comments>
		<pubDate>Mon, 27 Feb 2012 16:01:54 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4788</guid>
		<description><![CDATA[Among other great features, the new HTML5 specification allow native audio streaming. In this article, I have compiled the 10 most awesome HTML5 audio players available today.]]></description>
			<content:encoded><![CDATA[<h2>Media Element</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/mediaelement.png" alt="" /><br />
MediaElement is an audio an video player which is written in pure HTML5 and CSS. Older browsers are supported by Custom Flash and Silverlight players that mimic the HTML5 MediaElement API.<br />
Media Element is skinnable, and offers plugins for popular platforms such as <a href="http://wordpress.org/extend/plugins/media-element-html5-video-and-audio-player/">WordPress</a>, Drupal, Joomla, etc. </p>
<p><strong>&rarr; Visit <a href="http://mediaelementjs.com/">http://mediaelementjs.com/</a></strong></p>
<h2>Scott Andrew&#8217;s HTML5 audio player</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/scott.png" alt="" /><br />
This player is very minimalist but works well. Great to use when you do not need playlists or any fancy effects!</p>
<p><strong>&rarr; Visit <a href="http://www.scottandrew.com/pub/html5audioplayer/">http://www.scottandrew.com/pub/html5audioplayer/</a></strong></p>
<h2>Speakker</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/speakker.png" alt="" /><br />
Here is a great player, probably my favorite from the whole list. Speakker is super easy to set up and comes out of the box in two variations and with incredible options of customization: Flexible dimensions, unlimited colors, etc&#8230;<br />
Speakker is cross-browser compatible and have a Flash fallback for old browsers.<br />
and two different button sets for light and dark themes. </p>
<p><strong>&rarr; Visit <a href="http://www.speakker.com/">http://www.speakker.com/</a></strong></p>
<h2>MooTools HTML5 Audio Player</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/mootools.png" alt="" /><br />
Are you using Mootools on your website? If yes, you&#8217;ll probably enjoy this player, made with HTML5 and the Mootools JavaScript framework. The player works perfectly on all recent browsers.</p>
<p><strong>&rarr; Visit <a href="http://simulacre.org/mootools-html5-audio-player/">http://simulacre.org/mootools-html5-audio-player/</a></strong></p>
<h2>Universal HTML5 Audio Player</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/universal.png" alt="" /><br />
This player is the only one from the list which isn&#8217;t free. But it&#8217;s cheap ($5 only!) and works well. It have lots of useful features, such as a way to protect your audio from being hijacked by using a beep overlay, which is a great solution for commercial uses.</p>
<p><strong>&rarr; Visit <a href="http://codecanyon.net/item/universal-html5-audio-player/1104759?ref=jbj">http://codecanyon.net/item/universal-html5-audio-player</a></strong></p>
<h2>SoundManager 2</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/soundmanager.png" alt="" /><br />
Using HTML5 and Flash, SoundManager 2 provides reliable cross-platform audio under a single lightweight (10 kb) JavaScript API.<br />
Want to see what you can do with Sound Manager 2? Then visit <a href="http://wheelsofsteel.net/">http://wheelsofsteel.net/</a> for an awesome demo!</p>
<p><strong>&rarr; Visit <a href="http://www.schillmania.com/projects/soundmanager2/">http://www.schillmania.com/projects/soundmanager2/</a></strong></p>
<h2>jplayer</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/jplayer.png" alt="" /><br />
jplayer is a jQuery plugin which have been my audio player of choice for several months because of its simplicity. A great tool which can also play  videos. </p>
<p><strong>&rarr; Visit <a href="http://jplayer.org/">http://jplayer.org/</a></strong></p>
<h2>audio.js</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/audio.png" alt="" /><br />
audio.js is a drop-in javascript library that allows HTML5&#8242;s <code>&lt;audio&gt;</code> tag to be used anywhere. It uses native <code>&lt;audio&gt;</code> where available and an invisible flash player to emulate <code>&lt;audio&gt;</code> for other browsers. It provides a consistent html player UI to all browsers which can be styled used standard css.</p>
<p><strong>&rarr; Visit <a href="http://kolber.github.com/audiojs/">http://kolber.github.com/audiojs/</a></strong></p>
<h2>HTML5 Audio Player Bookmarklet</h2>
<p><img src="http://www.catswhocode.com/blog/wp-content/uploads/2012/02/bookmarklet.png" alt="" /><br />
This bookmarklet adds an audio player to play linked audio files on any page. It can be used on any page which has links to downloadable audio files. A great tool to stream audio instead of downloading!</p>
<p><strong>&rarr; Visit <a href="http://marklets.com/HTML5+Audio+Player.aspx">http://marklets.com/HTML5+Audio+Player.aspx</a></strong></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/b_Omv98boJ0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/10-awesome-html5-audio-players/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Introducing CatsWhoCode code snippet library!</title>
		<link>http://www.catswhocode.com/blog/introducing-catswhocode-code-snippet-library</link>
		<comments>http://www.catswhocode.com/blog/introducing-catswhocode-code-snippet-library#comments</comments>
		<pubDate>Mon, 13 Feb 2012 14:43:10 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4740</guid>
		<description><![CDATA[As a developer, I really like to collect code snippets that can be useful when needed. On CatsWhoCode, most popular posts are often the ones filled with lots of ready to use code snippets. This is why I decided to add a new feature to the site, the code snippet library.]]></description>
			<content:encoded><![CDATA[<h2>A code snippet library on CWC?</h2>
<p>Over the years, CatsWhoCode has become a place of interest for web developers. Most popular articles on the blog are those who showcase useful code snippets which can be used directly on your projects.</p>
<p>This is why I decided to go further in that direction, and create a place where people can easily find useful code snippets. I have added some snippets but for now the whole library looks a bit empty. Don&#8217;t worry, I add snippets everyday so it will not take very long until we have a consistent collection of code snippets!</p>
<p><strong>&rarr; <a href="http://www.catswhocode.com/blog/snippets">Visit CatsWhoCode.com code snippets library!</a></strong></p>
<h2>Submit your own snippets</h2>
<p>CWC code library allows developers to submit their own code snippets so they can share them with other developers. When submitting a code snippet, you are able to link to your own website so you&#8217;ll get (hopefully) a few visits to your website. The link is dofollow, so submitting quality snippets is also good for your SEO.</p>
<p>All submission will be manually approved or declined, to ensure the quality of the library. I rather focus on quality than quantity. Want to submit a cool code snippet? Go <a href="http://www.catswhocode.com/blog/submit-snippet">here</a>!</p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/7PoVrU7DSOs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/introducing-catswhocode-code-snippet-library/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Amazing things to do with PHP and cURL</title>
		<link>http://www.catswhocode.com/blog/amazing-things-to-do-with-php-and-curl</link>
		<comments>http://www.catswhocode.com/blog/amazing-things-to-do-with-php-and-curl#comments</comments>
		<pubDate>Mon, 06 Feb 2012 15:01:58 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4702</guid>
		<description><![CDATA[cURL, and its PHP extension libcURL, are very useful tools for tasks like simulating a web browser, submit forms or login to a web service. In this article, I’m going to show you some amazing things that you can do using PHP and cURL.]]></description>
			<content:encoded><![CDATA[<h2>Check if a specific website is available</h2>
<p>Want to know if a specific website is available? cURL is here to help. This script can be used with a cron job to monitor your websites.</p>
<p>Don&#8217;t forget to update the script with the url you want to check on line 3. Once done, just paste it somewhere and it will let you know about the site availability.</p>
<pre>
&lt;?php

       if (isDomainAvailible(&#39;http://www.css-tricks.com&#39;))
       {
               echo &quot;Up and running!&quot;;
       }
       else
       {
               echo &quot;Woops, nothing found there.&quot;;
       }

       //returns true, if domain is availible, false if not
       function isDomainAvailible($domain)
       {
               //check, if a valid url is provided
               if(!filter_var($domain, FILTER_VALIDATE_URL))
               {
                       return false;
               }

               //initialize curl
               $curlInit = curl_init($domain);
               curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
               curl_setopt($curlInit,CURLOPT_HEADER,true);
               curl_setopt($curlInit,CURLOPT_NOBODY,true);
               curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);

               //get answer
               $response = curl_exec($curlInit);

               curl_close($curlInit);

               if ($response) return true;

               return false;
       }
?&gt;
</pre>
<p><strong>&rarr; Source: <a href="http://css-tricks.com/snippets/php/check-if-website-is-available/">http://css-tricks.com/snippets/php/check-if-website-is-available/</a></strong></p>
<h2>cURL replacement for file_get_contents()</h2>
<p>The <code>file_get_contents()</code> function is very useful but it is unfortunely deactivated by default on some webhosts. Using cURL, we can write a replacement function that works exactly like <code>file_get_contents()</code>.</p>
<pre>
function file_get_contents_curl($url) {
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch, CURLOPT_URL, $url);

	$data = curl_exec($ch);
	curl_close($ch);

	return $data;
}
</pre>
<p><strong>&rarr; Source: <a href="http://snipplr.com/view/4084">http://snipplr.com/view/4084</a></strong></p>
<h2>Get latest Twitter status</h2>
<p>Using PHP and cURL, it is pretty easy to get the status of a specific user. Once you have it, what about displaying it on your blog, like I do in <a href="http://www.wprecipes.com">WPRecipes</a> footer?</p>
<pre class="brush: php">function get_status($twitter_id, $hyperlinks = true) {
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1");
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $src = curl_exec($c);
    curl_close($c);
    preg_match('/&lt;text&gt;(.*)&lt;\/text&gt;/', $src, $m);
    $status = htmlentities($m[1]);
    if( $hyperlinks ) $status = ereg_replace("[[:alpha:]]+://[^&lt;&gt;[:space:]]+[[:alnum:]/]", '&lt;a href="%5C%22%5C%5C0%5C%22"&gt;\\0&lt;/a&gt;', $status);
    return($status);
}</pre>
<p>The function is super easy to use:</p>
<pre>echo get_status('catswhocode');</pre>
<p><strong>&rarr; Source: <a href="http://www.catswhocode.com/blog/php-snippets-to-interact-with-twitter">http://www.catswhocode.com/blog/php-snippets-to-interact-with-twitter</a></strong></p>
<h2>Twitter: test friendship between two users</h2>
<p>If you want to know if a specific user is following you (or someone else) you have to use the Twitter API. This snippet will echo <code>true</code> if the two users specified on lines 18 and 19 are friends. It will return <code>false</code> otherwise.</p>
<pre>
function make_request($url) {
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	$result = curl_exec($ch);
	curl_close($ch);
	return $result;
}

/* gets the match */
function get_match($regex,$content) {
	preg_match($regex,$content,$matches);
	return $matches[1];
}

/* persons to test */
$person1 = 'phpsnippets';
$person2 = 'catswhocode';

/* send request to twitter */
$url = 'https://api.twitter.com/1/friendships/exist';
$format = 'xml';

/* check */
$persons12 = make_request($url.'.'.$format.'?user_a='.$person1.'&amp;user_b='.$person2);
$result = get_match('/&lt;friends&gt;(.*)&lt;\/friends&gt;/isU',$persons12);
echo $result; // returns "true" or "false"
</pre>
<p><strong>&rarr; Source: <a href="http://www.catswhocode.com/blog/php-snippets-to-interact-with-twitter">http://www.catswhocode.com/blog/php-snippets-to-interact-with-twitter</a></strong></p>
<h2>Download and save images from a page using cURL</h2>
<p>Here is a set of functions that can be very useful: Give this script the url of a webpage, and it will save all images from this page on your server.</p>
<pre>
function getImages($html) {
    $matches = array();
    $regex = &#39;~http://somedomain.com/images/(.*?)\.jpg~i&#39;;
    preg_match_all($regex, $html, $matches);
    foreach ($matches[1] as $img) {
        saveImg($img);
    }
}

function saveImg($name) {
    $url = &#39;http://somedomain.com/images/&#39;.$name.&#39;.jpg&#39;;
    $data = get_data($url);
    file_put_contents(&#39;photos/&#39;.$name.&#39;.jpg&#39;, $data);
}

$i = 1;
$l = 101;

while ($i &lt; $l) {
    $html = get_data(&#39;http://somedomain.com/id/&#39;.$i.&#39;/&#39;);
    getImages($html);
    $i += 1;
}
</pre>
<p><strong>&rarr; Source: <a href="http://stackoverflow.com/questions/7747875/grab-download-images-from-multiple-pages-using-php-preg-match-all-curl">http://stackoverflow.com/questions/7747875/grab-download-images-from-multiple-pages-using-php-preg-match-all-curl</a></strong></p>
<h2>Convert currencies using cURl and Google</h2>
<p>Converting currencies isn&#8217;t very hard to do, but as the currencies fluctuates all the time, we definitely need to use a service like Google to get the most recent values. The <code>currency()</code> function take 3 parameters: from, to, and sum. </p>
<pre>
function currency($from_Currency,$to_Currency,$amount) {
    $amount = urlencode($amount);
    $from_Currency = urlencode($from_Currency);
    $to_Currency = urlencode($to_Currency);
    $url = &quot;http://www.google.com/ig/calculator?hl=en&amp;q=$amount$from_Currency=?$to_Currency&quot;;
    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,  CURLOPT_USERAGENT , &quot;Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)&quot;);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $rawdata = curl_exec($ch);
    curl_close($ch);
    $data = explode(&#39;&quot;&#39;, $rawdata);
    $data = explode(&#39; &#39;, $data[&#39;3&#39;]);
    $var = $data[&#39;0&#39;];
    return round($var,2);
}
</pre>
<p><strong>&rarr; Source: <a href="http://l33ts.org/forum/Thread-PHP-Convert-currencies-using-Google-and-cURL-Snippet">http://l33ts.org/forum/Thread-PHP-Convert-currencies-using-Google-and-cURL-Snippet</a></strong></p>
<h2>Get remote filesize using cURL</h2>
<p>Want to be able to calculate the size of a specific file? The following function can help. It takes 3 parameters: the file url, and in case the file is password protected, a username and a password.</p>
<pre>
function remote_filesize($url, $user = &quot;&quot;, $pw = &quot;&quot;){
    ob_start();
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 1);

    if(!empty($user) &amp;&amp; !empty($pw))
    {
        $headers = array(&#39;Authorization: Basic &#39; .  base64_encode(&quot;$user:$pw&quot;));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }

    $ok = curl_exec($ch);
    curl_close($ch);
    $head = ob_get_contents();
    ob_end_clean();

    $regex = &#39;/Content-Length:\s([0-9].+?)\s/&#39;;
    $count = preg_match($regex, $head, $matches);

    return isset($matches[1]) ? $matches[1] : &quot;unknown&quot;;
}
</pre>
<p><strong>&rarr; Source: <a href="http://megasnippets.com/source-codes/php/get_remote_filesize">http://megasnippets.com/source-codes/php/get_remote_filesize</a></strong></p>
<h2>FTP upload with cURL</h2>
<p>PHP does have a FTP library, but you can also use cURL to upload files on a FTP server. Here is a working example:</p>
<pre>
// open a file pointer
$file = fopen("/path/to/file", "r");

// the url contains most of the info needed
$url = "ftp://username:password@mydomain.com:21/path/to/new/file";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// upload related options
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize("/path/to/file"));

// set for ASCII mode (e.g. text files)
curl_setopt($ch, CURLOPT_FTPASCII, 1);

$output = curl_exec($ch);
curl_close($ch);
</pre>
<p><strong>&rarr; Source: <a href="http://net.tutsplus.com/tutorials/php/techniques-and-resources-for-mastering-curl/">http://net.tutsplus.com/tutorials/php/techniques-and-resources-for-mastering-curl/</a></strong></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/-nXlJoG2MOQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/amazing-things-to-do-with-php-and-curl/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>WordPress Transients API – Practical examples</title>
		<link>http://www.catswhocode.com/blog/wordpress-transients-api-practical-examples</link>
		<comments>http://www.catswhocode.com/blog/wordpress-transients-api-practical-examples#comments</comments>
		<pubDate>Mon, 23 Jan 2012 15:04:54 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.catswhocode.com/blog/?p=4688</guid>
		<description><![CDATA[The WordPress Transients API is a very useful tool which allow developers to cache data such as the result of a query for future uses. In this article, I've compiled a list of useful practical example to div into the power of WordPress Transients API. ]]></description>
			<content:encoded><![CDATA[<h2>What is the transients API, and why it&#8217;s useful</h2>
<p>Most developers who worked with WordPress in the past probably ever heard of the Options API, which allow you to save, update and delete custom values. The Transients API is pretty similar to the Options API, but with the feature of an expiration time, which simplifies the process of using the <code>wp_options</code> database table to store cached information.</p>
<p>After you read the practical example I&#8217;ve listed on this post, I suggest you to read the <a href="http://codex.wordpress.org/Transients_API">Transients API  page</a> on WordPress Codex.</p>
<h2>List sites from your network</h2>
<p>Let&#8217;s start with an interesting snippet for those who run networks of many blogs. The code below display a general menu of all sites from your networks. In this case, transients are used to store the data for a defined time (which can be set using the <code>$expires</code> variable on line 1) so you&#8217;ll not make huge database calls each time your menu have to be displayed.</p>
<p>To use this snippet, first you have to paste the function into your <code>functions.php</code> file. </p>
<pre>
function wp_list_sites( $expires = 7200 ) {
   if( !is_multisite() ) return false;

   // Because the get_blog_list() function is currently flagged as deprecated
   // due to the potential for high consumption of resources, we&#39;ll use
   // $wpdb to roll out our own SQL query instead. Because the query can be
   // memory-intensive, we&#39;ll store the results using the Transients API
   if ( false === ( $site_list = get_transient( &#39;multisite_site_list&#39; ) ) ) {
      global $wpdb;
      $site_list = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&#39;SELECT * FROM wp_blogs ORDER BY blog_id&#39;) );
      // Set the Transient cache to expire every two hours
      set_site_transient( &#39;multisite_site_list&#39;, $site_list, $expires );
   }

   $current_site_url = get_site_url( get_current_blog_id() );

   $html = &#39;
&lt;ul id=&quot;network-menu&quot;&gt;&#39; . &quot;\n&quot;;

   foreach ( $site_list as $site ) {
      switch_to_blog( $site-&gt;blog_id );
      $class = ( home_url() == $current_site_url ) ? &#39; class=&quot;current-site-item&quot;&#39; : &#39;&#39;;
      $html .= &quot;\t&quot; . &#39;
&lt;li id=&quot;site-&#39; . $site-&gt;blog_id . &#39;&quot; &#39;=&quot;&quot; .=&quot;&quot; $class=&quot;&quot;&gt;&lt;a href=&quot;&#39; . home_url() . &#39;&quot;&gt;&#39; . get_bloginfo(&#39;name&#39;) . &#39;&lt;/a&gt;&lt;/li&gt;

&#39; . &quot;\n&quot;;
      restore_current_blog();
   }

   $html .= &#39;&lt;/ul&gt;

&lt;!--// end #network-menu --&gt;&#39; . &quot;\n\n&quot;;

   return $html;
}
</pre>
<p>Once done, the following code will display all sites from your network. Simply paste it on any of theme files, where you want the list to be displayed.</p>
<pre>
&lt;?php
// Multisite Network Menu
$network_menu = wp_list_sites();
if( $network_menu ):
?&gt;
&lt;div id=&quot;network-menu&quot;&gt;
   &lt;?php echo $network_menu; ?&gt;
&lt;/div&gt;

&lt;!--// end #network-menu --&gt;
&lt;?php endif; ?&gt;
</pre>
<p><strong>&rarr; Source: <a href="http://wp.smashingmagazine.com/2011/11/17/wordpress-multisite-practical-functions-methods/">http://wp.smashingmagazine.com/2011/11/17/wordpress&#8230;/</a></strong></p>
<h2>Twitter followers count using WordPress transients</h2>
<p>Many blogs, including this one, are displaying how many people are following them on Twitter. It&#8217;s quite easy to grab some json data, but it takes a significant amount of time. Using transients allow you to grab the json data from Twitter once a day, and store it in your database for future uses.</p>
<p>Simply paste the function below into your <code>functions.php</code> file: </p>
<pre>
function my_followers_count($screen_name = &#39;kovshenin&#39;){
	$key = &#39;my_followers_count_&#39; . $screen_name;

	// Let&#39;s see if we have a cached version
	$followers_count = get_transient($key);
	if ($followers_count !== false)
		return $followers_count;
	else
	{
		// If there&#39;s no cached version we ask Twitter
		$response = wp_remote_get(&quot;http://api.twitter.com/1/users/show.json?screen_name={$screen_name}&quot;);
		if (is_wp_error($response))
		{
			// In case Twitter is down we return the last successful count
			return get_option($key);
		}
		else
		{
			// If everything&#39;s okay, parse the body and json_decode it
			$json = json_decode(wp_remote_retrieve_body($response));
			$count = $json-&gt;followers_count;

			// Store the result in a transient, expires after 1 day
			// Also store it as the last successful using update_option
			set_transient($key, $count, 60*60*24);
			update_option($key, $count);
			return $count;
		}
	}
}

echo &quot;I have &quot; . my_followers_count(&#39;kovshenin&#39;) . &quot; followers&quot;;
</pre>
<p><strong>&rarr; Source: <a href="http://kovshenin.com/2010/05/twitter-followers-count-snippet-for-wordpress-2253/">http://kovshenin.com/2010/05/twitter-followers-count-snippet-for-wordpress-2253/</a></strong></p>
<h2>RSS subscribers count using WordPress transients</h2>
<p>Using exactly the same technique as demonstrated above, we can grab RSS subscribers and store the result in WordPress database. Don&#8217;t forget to update the code with your own feedburner url on line 2. Then, paste the code where you&#8217;d like to display how many RSS feed readers you have. </p>
<pre>
function feed_subscribers(){
        $feed_url = &#39;http://feeds.feedburner.com/yourname&#39;;
        $count = get_transient(&#39;feed_count&#39;);
        if ($count != false) return $count;
	$count = 0;
        $data  = wp_remote_get(&#39;http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=&#39;.$feed_url.&#39;&#39;);
   if (is_wp_error($data)) {
        return &#39;error&#39;;
   }else{
	$body = wp_remote_retrieve_body($data);
	$xml = new SimpleXMLElement($body);
	$status = $xml-&gt;attributes();
	if ($status == &#39;ok&#39;) {
		$count = $xml-&gt;feed-&gt;entry-&gt;attributes()-&gt;circulation;
	} else {
		$count = 300; // fallback number
	}
   }
	set_transient(&#39;feed_count&#39;, $count, 60*60*24); // 24 hour cache
	echo $count;
}
</pre>
<p><strong>&rarr; Source: <a href="https://wpsnipp.com/index.php/functions-php/get-feedburner-count-using-get_transient-and-wp_remote_get/">https://wpsnipp.com/index.php/functions-php/get-feedburner-count-using-get_transient-and-wp_remote_get/</a></strong></p>
<h2>Cached navigation menu</h2>
<p>Introduced in WordPress 3.0, the new menu system is definitely an improvement to WordPress. But using transients, we can even do something better, a menu with the same functionality but without the huge database requests.</p>
<pre>
&lt;?php
/**
 * Wrapper function around wp_nav_menu() that will cache the wp_nav_menu for all tag/category
 * pages used in the nav menus
 * @see http://lookup.hitchhackerguide.com/wp_nav_menu for $args
 * @author tott
 */ 
function hh_cached_nav_menu( $args = array(), $prime_cache = false ) {
	global $wp_query;

	$queried_object_id = empty( $wp_query-&gt;queried_object_id ) ? 0 : (int) $wp_query-&gt;queried_object_id;

	// If design of navigation menus differs per queried object use the key below
	// $nav_menu_key = md5( serialize( $args ) . &#39;-&#39; . $queried_object_id );

	// Otherwise
	$nav_menu_key = md5( serialize( $args ) );

	$my_args = wp_parse_args( $args );
	$my_args = apply_filters( &#39;wp_nav_menu_args&#39;, $my_args );
	$my_args = (object) $my_args;

	if ( ( isset( $my_args-&gt;echo ) &amp;&amp; true === $my_args-&gt;echo ) || !isset( $my_args-&gt;echo ) ) {
		$echo = true;
	} else {
		$echo = false;
	}

	$skip_cache = false;
	$use_cache = ( true === $prime_cache ) ? false : true;

	// If design of navigation menus differs per queried object comment out this section
	//*
	if ( is_singular() ) {
		$skip_cache = true;
	} else if ( !in_array( $queried_object_id, hh_get_nav_menu_cache_objects( $use_cache ) ) ) {
		$skip_cache = true;
	}
	//*/

	if ( true === $skip_cache || true === $prime_cache || false === ( $nav_menu = get_transient( $nav_menu_key ) ) ) {
		if ( false === $echo ) {
			$nav_menu = wp_nav_menu( $args );
		} else {
			ob_start();
			wp_nav_menu( $args );
			$nav_menu = ob_get_clean();
		}
		if ( false === $skip_cache )
			set_transient( $nav_menu_key, $nav_menu );
	} 
	if ( true === $echo )
		echo $nav_menu;
	else
		return $nav_menu;
}

/**
 * Invalidate navigation menu when an update occurs
 */
function hh_update_nav_menu_objects( $menu_id = null, $menu_data = null ) {
	hh_cached_nav_menu( array( &#39;echo&#39; =&gt; false ), $prime_cache = true );
}
add_action( &#39;wp_update_nav_menu&#39;, &#39;hh_update_nav_menu_objects&#39; );

/** 
 * Helper function that returns the object_ids we&#39;d like to cache
 */
function hh_get_nav_menu_cache_objects( $use_cache = true ) {
	$object_ids = get_transient( &#39;hh_nav_menu_cache_object_ids&#39; );
	if ( true === $use_cache &amp;&amp; !empty( $object_ids ) ) {
		return $object_ids;
	}

	$object_ids = $objects = array();

	$menus = wp_get_nav_menus();
	foreach ( $menus as $menu_maybe ) {
		if ( $menu_items = wp_get_nav_menu_items( $menu_maybe-&gt;term_id ) ) {
			foreach( $menu_items as $menu_item ) {
				if ( preg_match( &quot;#.*/category/([^/]+)/?$#&quot;, $menu_item-&gt;url, $match ) )
					$objects[&#39;category&#39;][] = $match[1];
				if ( preg_match( &quot;#.*/tag/([^/]+)/?$#&quot;, $menu_item-&gt;url, $match ) )
					$objects[&#39;post_tag&#39;][] = $match[1];
			}
		}
	}
	if ( !empty( $objects ) ) {
		foreach( $objects as $taxonomy =&gt; $term_names ) {
			foreach( $term_names as $term_name ) {
				$term = get_term_by( &#39;slug&#39;, $term_name, $taxonomy );
				if ( $term )
					$object_ids[] = $term-&gt;term_id;
			}
		}
	}

	$object_ids[] = 0; // that&#39;s for the homepage

	set_transient( &#39;hh_nav_menu_cache_object_ids&#39;, $object_ids );
	return $object_ids;
}
</pre>
<p><strong>&rarr; Source: <a href="http://hitchhackerguide.com/2011/10/07/caching-wordpress-navigation-menus-wp_nav_menu-wrapper/">http://hitchhackerguide.com/2011/10/07/caching-wordpress-navigation-menus-wp_nav_menu-wrapper/</a></strong></p>
<h2>Cached Tag cloud</h2>
<p>Thanks to WordPress transients API, caching almost anything is definitely. The following example shows how to cache the good old tag cloud. Simply paste this code wherever you want you tag cloud to be displayed.</p>
<pre>
$tag_cloud = get_transient( 'tag_cloud' );
if ( false === $tag_cloud || '' === $tag_cloud ){
	$args = array('echo' => false);
	$tag_cloud = wp_tag_cloud( $args );
	set_transient( 'tag_cloud', $tag_cloud, 60*60*12 );
}
echo $tag_cloud;
</pre>
<p><strong>&rarr; Source: <a href="http://wpengineer.com/2148/simple-cache-with-the-wordpress-transient-api/">http://wpengineer.com/2148/simple-cache-with-the-wordpress-transient-api/</a></strong></p>
<h2>Caching any custom query using transients</h2>
<p>Is your theme using custom queries? If yes, you should definitely use the transients API to cache the queries. The following code shows how to cache a custom query. As you can see, there&#8217;s nothing complicated at all.</p>
<pre>
&lt;?php
// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( &#39;special_query_results&#39; ) ) ) {
    // It wasn&#39;t there, so regenerate the data and save the transient
     $special_query_results = new WP_Query( &#39;cat=5&amp;order=random&amp;tag=tech&amp;post_meta_key=thumbnail&#39; );
     set_transient( &#39;special_query_results&#39;, $special_query_results );
}

// Use the data like you would have normally...
?&gt;
</pre>
<p><strong>&rarr; Source: <a href="http://codex.wordpress.org/Transients_API">http://codex.wordpress.org/Transients_API</a></strong></p>
<img src="http://feeds.feedburner.com/~r/Catswhocode/~4/mWn008nUMo8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.catswhocode.com/blog/wordpress-transients-api-practical-examples/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

