<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Solution Hacker</title>
	<atom:link href="http://www.solutionhacker.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.solutionhacker.com</link>
	<description>This blog provides solutions for enterpreneurs!</description>
	<lastBuildDate>Fri, 18 May 2012 08:13:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>WordPress for Developer &#8211; Quick Reference</title>
		<link>http://www.solutionhacker.com/wordpress-for-developer-quick-reference/</link>
		<comments>http://www.solutionhacker.com/wordpress-for-developer-quick-reference/#comments</comments>
		<pubDate>Wed, 16 May 2012 05:30:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Build Money Site]]></category>
		<category><![CDATA[Earn Money Online]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=1166</guid>
		<description><![CDATA[<h2>How data is being stored?</h2>
In wordpress, common data like <strong>author, date, title, excerpt, content, status and post type</strong> are being stored in <strong>wp_posts</strong>. Whereas, the data like <strong>attribute</strong> info of the post are being stored in <strong>wp_postmeta</strong>. The attributes are custom fields that you can be defined for specific post type. I have installed a nice shopping theme that defines a set of custom post type and each has its own custom attributes. I have installed maya shop theme and loaded it with sample data. I want to know how the product data is structured and I found out the following:

The data of the products are split into 2 groups. The first group are regular post info like author, title, content and status are stored in the wp_posts. The other group contains some product specific fields like price, size, stock status and etc are stored in the wp_postmeta. It is a typical approach that most of the custom post type follow. However, it is an inefficient way to store product info. For example, a single product  in catalog now appears in 2 tables and custom fields in the example are up to 50 fields. As you can calculate, one product will occupy ~50 rows in wp_postmeta. If my catalog has 5000 products, it has about 250K rows. It is not that bad. But once your catalog grows 4 times, it already reaches 1 millions rows. Apart form that, update product info could span across multiple rows in multiple tables as well. To me, it is a trade-off between flexibility and scalability/ performance.

You may notice that the <strong>category</strong> and <strong>tag</strong> are not stored in either of these tables. These info are stored:
<ul>
	<li><strong>wp_terms</strong> (term_id, name, slug)</li>
	<li><strong>wp_term_relationships</strong> (object_id,  term_taxonomy_id)</li>
	<li><strong>wp_term_taxonomy</strong> (term_taxonomy_id,  term_id, taxonomy, description, parent, count)<strong></strong></li>
</ul>
WordPress comes with<strong> 3 taxonomies, post tag, categories, link categories.</strong>
<ul>
	<li> <em>Post Tag:</em> acts like a label, attached to a post.<em></em></li>
	<li><em>Category: </em>acts like a “bucket” in which we put  posts, are often hierarchical. Posts can live in multiple categories.<em></em></li>
	<li><em>Link Category:</em> acts like a label, attached to a  link.</li>
</ul>
Each tag or category you create is a “term” within that taxonomy. For  example, if you create a category “Movies” (in our site about  entertainment), “Movies” becomes a term within the category  taxonomy.
<h2></h2>
<h2>How can devleoper access the data in wordpress?</h2>
To access the data, we need to get the database handle. In wordpress, you can use <strong>wpdb</strong> as the handle.

<strong>Query returns &#62; 1 rows:</strong>

Generic, mulitple row results can be pulled from the database with <code>get_results</code>. The function returns the entire query result as an array. Each element of this array corresponds to one row of the query result and, like <code>get_row</code>, can be an object, an associative array, or a numbered array.
<ul>
	<li>$fivesdrafts = $wpdb-&#62;get_results("SELECT ID, post_title FROM $wpdb-&#62;posts WHERE post_status = 'draft' AND post_author = 5");</li>
</ul>
<strong>Query return 1 row:</strong>
<ul>
	<li>$wpdb-&#62;get_row("SELECT * FROM $wpdb-&#62;links WHERE link_id = 10");</li>
</ul>
<strong>Query returns a single field value:</strong>
<ul>
	<li>$user_count = $wpdb-&#62;get_var( $wpdb-&#62;prepare( "SELECT COUNT(*) FROM $wpdb-&#62;users;" ) );</li>
</ul>
<strong>Select a row</strong>:
<ul>
	<li>output type can be: OBJECT, ARRAY_A (associative array), ARRAY_N (numeric indexed array). Offset defaults to 0.</li>
	<li>$mylink = $wpdb-&#62;get_row("SELECT * FROM $wpdb-&#62;links WHERE link_id = 10", ARRAY_A);</li>
</ul>
<strong>Generic method:</strong>
<ul>
	<li>$wpdb-&#62;query($wpdb-&#62;prepare("DELETE FROM $wpdb-&#62;postmeta WHERE post_id = '13'", $id, $key )</li>
</ul>]]></description>
			<content:encoded><![CDATA[<h2>How data is being stored?</h2>
<p>In wordpress, common data like <strong>author, date, title, excerpt, content, status and post type</strong> are being stored in <strong>wp_posts</strong>. Whereas, the data like <strong>attribute</strong> info of the post are being stored in <strong>wp_postmeta</strong>. The attributes are custom fields that you can be defined for specific post type. I have installed a nice shopping theme that defines a set of custom post type and each has its own custom attributes. I have installed maya shop theme and loaded it with sample data. I want to know how the product data is structured and I found out the following:</p>
<p>The data of the products are split into 2 groups. The first group are regular post info like author, title, content and status are stored in the wp_posts. The other group contains some product specific fields like price, size, stock status and etc are stored in the wp_postmeta. It is a typical approach that most of the custom post type follow. However, it is an inefficient way to store product info. For example, a single product  in catalog now appears in 2 tables and custom fields in the example are up to 50 fields. As you can calculate, one product will occupy ~50 rows in wp_postmeta. If my catalog has 5000 products, it has about 250K rows. It is not that bad. But once your catalog grows 4 times, it already reaches 1 millions rows. Apart form that, update product info could span across multiple rows in multiple tables as well. To me, it is a trade-off between flexibility and scalability/ performance.</p>
<p>You may notice that the <strong>category</strong> and <strong>tag</strong> are not stored in either of these tables. These info are stored:</p>
<ul>
<li><strong>wp_terms</strong> (term_id, name, slug)</li>
<li><strong>wp_term_relationships</strong> (object_id,  term_taxonomy_id)</li>
<li><strong>wp_term_taxonomy</strong> (term_taxonomy_id,  term_id, taxonomy, description, parent, count)<strong></strong></li>
</ul>
<p>WordPress comes with<strong> 3 taxonomies, post tag, categories, link categories.</strong></p>
<ul>
<li> <em>Post Tag:</em> acts like a label, attached to a post.<em></em></li>
<li><em>Category: </em>acts like a “bucket” in which we put  posts, are often hierarchical. Posts can live in multiple categories.<em></em></li>
<li><em>Link Category:</em> acts like a label, attached to a  link.</li>
</ul>
<p>Each tag or category you create is a “term” within that taxonomy. For  example, if you create a category “Movies” (in our site about  entertainment), “Movies” becomes a term within the category  taxonomy.</p>
<h2></h2>
<h2>How can devleoper access the data in wordpress?</h2>
<p>To access the data, we need to get the database handle. In wordpress, you can use <strong>wpdb</strong> as the handle.</p>
<p><strong>Query returns &gt; 1 rows:</strong></p>
<p>Generic, mulitple row results can be pulled from the database with [code]]czoxMTpcImdldF9yZXN1bHRzXCI7e1smKiZdfQ==[[/code]. The function returns the entire query result as an array. Each element of this array corresponds to one row of the query result and, like [code]]czo3OlwiZ2V0X3Jvd1wiO3tbJiomXX0=[[/code], can be an object, an associative array, or a numbered array.</p>
<ul>
<li>$fivesdrafts = $wpdb-&gt;get_results("SELECT ID, post_title FROM $wpdb-&gt;posts WHERE post_status = 'draft' AND post_author = 5");</li>
</ul>
<p><strong>Query return 1 row:</strong></p>
<ul>
<li>$wpdb-&gt;get_row("SELECT * FROM $wpdb-&gt;links WHERE link_id = 10");</li>
</ul>
<p><strong>Query returns a single field value:</strong></p>
<ul>
<li>$user_count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( "SELECT COUNT(*) FROM $wpdb-&gt;users;" ) );</li>
</ul>
<p><strong>Select a row</strong>:</p>
<ul>
<li>output type can be: OBJECT, ARRAY_A (associative array), ARRAY_N (numeric indexed array). Offset defaults to 0.</li>
<li>$mylink = $wpdb-&gt;get_row("SELECT * FROM $wpdb-&gt;links WHERE link_id = 10", ARRAY_A);</li>
</ul>
<p><strong>Generic method:</strong></p>
<ul>
<li>$wpdb-&gt;query($wpdb-&gt;prepare("DELETE FROM $wpdb-&gt;postmeta WHERE post_id = '13'", $id, $key )</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/wordpress-for-developer-quick-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing &#8211; Async method</title>
		<link>http://www.solutionhacker.com/unit-testing-async-method/</link>
		<comments>http://www.solutionhacker.com/unit-testing-async-method/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 07:05:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=1118</guid>
		<description><![CDATA[Most Unit testing frameworks assumes a synchronous call model that the calling thread will block until the called method returns. So a typical test method will look like the following ...

[code lang="java"]

class SyncServiceTest {
   @Test
   void testSyncCall() {
     Object input = ...
     Object expectedOutput = ...
     SyncService syncService = new SyncService();
     assertEqual(syncService.call(input), expectedOutput);
   }
 }

[/code]

However, this model doesn't fit if the call is asynchronous; ie: the calling thread is not blocked and the result will come later from a separated callback thread. For example, if you have the following AsyncService, where the "call()" method returns immediately and the result comes back from a callback interface.

[code lang="java"]

class AsyncService {
   public static interface ResultHandler {
      void handleResult(Object result);
   }

   ResultHandler resultHandler;

   public AsyncService(ResultHandler resultHandler) {
      this.resultHandler = resultHandler;
   }

   public void call(final Object request) throws InterruptedException {
      Executor executor =
         new ThreadedExecutor().execute(new Runnable() {
            public void run() {
               Object result = process(request);
               resultHandler.handleResult(result);
            }
         });
   }
}

[/code]

The test method need to be changed. You need to block the calling thread until the result comes back from the callback thread. The modified test code will look like the following ...

[code lang="java"]

class AsyncServiceTest {

   Object response;

   @Test
   public void testAsyncCall() {
      Object input = ...
      Object expectedOutput = ...
      final Latch latch = new Latch();

      AsyncCall asyncCall =
         new AsyncCall(new AsyncCall.ResultHandler() {
            public void handleResult(Object result) {
               response = result;
               latch.release();
            }
         });

      asyncCall.call(input);
      latch.attempt(3000);
      assertEquals(response, expectedOutput);
   }
}

[/code]

In this test method, the calling thread is waiting for the callback thread. A latch is used for the synchronization. You cannot use Thread.wait() and Thread.notify() for this purpose because there is a possibility that notify can be called before the wait and then one thread will wait indefinitely. Latch is a once-off switch and if the "release" is called first, then all subsequent "attempt" call will return immediately.]]></description>
			<content:encoded><![CDATA[<p>Most Unit testing frameworks assumes a synchronous call model that the calling thread will block until the called method returns. So a typical test method will look like the following &#8230;</p>
<pre class="brush: java; title: ; notranslate">

class SyncServiceTest {
   @Test
   void testSyncCall() {
     Object input = ...
     Object expectedOutput = ...
     SyncService syncService = new SyncService();
     assertEqual(syncService.call(input), expectedOutput);
   }
 }
</pre>
<p>However, this model doesn&#8217;t fit if the call is asynchronous; ie: the calling thread is not blocked and the result will come later from a separated callback thread. For example, if you have the following AsyncService, where the &#8220;call()&#8221; method returns immediately and the result comes back from a callback interface.</p>
<pre class="brush: java; title: ; notranslate">

class AsyncService {
   public static interface ResultHandler {
      void handleResult(Object result);
   }

   ResultHandler resultHandler;

   public AsyncService(ResultHandler resultHandler) {
      this.resultHandler = resultHandler;
   }

   public void call(final Object request) throws InterruptedException {
      Executor executor =
         new ThreadedExecutor().execute(new Runnable() {
            public void run() {
               Object result = process(request);
               resultHandler.handleResult(result);
            }
         });
   }
}
</pre>
<p>The test method need to be changed. You need to block the calling thread until the result comes back from the callback thread. The modified test code will look like the following &#8230;</p>
<pre class="brush: java; title: ; notranslate">

class AsyncServiceTest {

   Object response;

   @Test
   public void testAsyncCall() {
      Object input = ...
      Object expectedOutput = ...
      final Latch latch = new Latch();

      AsyncCall asyncCall =
         new AsyncCall(new AsyncCall.ResultHandler() {
            public void handleResult(Object result) {
               response = result;
               latch.release();
            }
         });

      asyncCall.call(input);
      latch.attempt(3000);
      assertEquals(response, expectedOutput);
   }
}
</pre>
<p>In this test method, the calling thread is waiting for the callback thread. A latch is used for the synchronization. You cannot use Thread.wait() and Thread.notify() for this purpose because there is a possibility that notify can be called before the wait and then one thread will wait indefinitely. Latch is a once-off switch and if the &#8220;release&#8221; is called first, then all subsequent &#8220;attempt&#8221; call will return immediately.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/unit-testing-async-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear Regression</title>
		<link>http://www.solutionhacker.com/linear-regression/</link>
		<comments>http://www.solutionhacker.com/linear-regression/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 15:09:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Machine Learning]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=1005</guid>
		<description><![CDATA[The idea is to find a line to best fits a set of points in the scatterplot. Before you do that, you should visualize the points on the scatterplot first and make sure they are not:
<ul>
	<li>non-linear</li>
	<li>random</li>
</ul>
Once you feel that the data points should be best fit for a straight line, you apply a formula to find out the best way to draw a line that has the least square distance summation across all the data points. This video will give you the detail.
<div class="youtube" style="width: 350; height: 300;"><object width="350" height="300" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://www.youtube.com/v/xojW6OEDfC4" /><embed width="350" height="300" type="application/x-shockwave-flash" src="http://www.youtube.com/v/xojW6OEDfC4" wmode="transparent" /></object></div>
The data points showing on the scatterpoint above represents the training set that tells you what x gives out what y. Here the x is a single feature. For example, you are trying to determine the relationship of house size with price where x=house size and y=price. However, we all know that house price should be determined by many factors. To name a few:
<ul>
	<li>Number of Bedrooms</li>
	<li>Number of Bathrooms</li>
	<li>Location</li>
	<li>Year of Built</li>
	<li>etc</li>
</ul>
If you try to combine those input features to predict the house price, then your data points will be in a<strong> multidimensional space</strong>. To find a line to best fit all the points in a multidimensional space is how we use to build the <strong>prediction model</strong> for house pricing.]]></description>
			<content:encoded><![CDATA[<p>The idea is to find a line to best fits a set of points in the scatterplot. Before you do that, you should visualize the points on the scatterplot first and make sure they are not:</p>
<ul>
<li>non-linear</li>
<li>random</li>
</ul>
<p>Once you feel that the data points should be best fit for a straight line, you apply a formula to find out the best way to draw a line that has the least square distance summation across all the data points. This video will give you the detail.</p>
<div class="youtube" style="width: 350; height: 300;"><object width="350" height="300" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://www.youtube.com/v/xojW6OEDfC4" /><embed width="350" height="300" type="application/x-shockwave-flash" src="http://www.youtube.com/v/xojW6OEDfC4" wmode="transparent" /></object></div>
<p>The data points showing on the scatterpoint above represents the training set that tells you what x gives out what y. Here the x is a single feature. For example, you are trying to determine the relationship of house size with price where x=house size and y=price. However, we all know that house price should be determined by many factors. To name a few:</p>
<ul>
<li>Number of Bedrooms</li>
<li>Number of Bathrooms</li>
<li>Location</li>
<li>Year of Built</li>
<li>etc</li>
</ul>
<p>If you try to combine those input features to predict the house price, then your data points will be in a<strong> multidimensional space</strong>. To find a line to best fit all the points in a multidimensional space is how we use to build the <strong>prediction model</strong> for house pricing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/linear-regression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Cheat Sheet</title>
		<link>http://www.solutionhacker.com/css-cheat-sheet/</link>
		<comments>http://www.solutionhacker.com/css-cheat-sheet/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 04:15:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Site Building]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=983</guid>
		<description><![CDATA[[box title="CSS Selector" color="#333333"]
<ol>
	<li>*  //universal selector</li>
	<li>#container *  //everything under #container element</li>
	<li>X  //all elements according to their type like ul, a, li, etc</li>
	<li>X:visited, X:link  //pseudo-class targeting - eg. input[type=radio]:checked</li>
	<li>#X : id selector    //target single element</li>
	<li>.X : class selector //target multiple elements</li>
	<li>X Y: descendant selector //select only a set of elements under X</li>
	<li>X &#62; Y  //only direct children Y of X</li>
	<li>X + Y //first adjacent sibling selector: select only the Y that is preceded by X (eg. ul + p)</li>
	<li>X ~ Y //all sibling selector</li>
	<li>X[Y]  //attribute selector (select X if it has Y as attribute)</li>
	<li>X[Y="Z"] //conditional attribute selector : exact</li>
	<li>X[Y*="Z"] //conditional attribute selector: contains</li>
	<li>X[Y^="Z"] //conditional attribute selector: begins with</li>
	<li>X[Y$="Z"] //conditional attribute selector: end with</li>
	<li>X[Y~="Z"] //target an attribute which has a spaced-separated list of values</li>
	<li>X:not(selector)</li>
</ol>
Use those tag to help you generated content around the selected elements
<ol>
	<li>X:after</li>
	<li>X:before</li>
	<li>X:hover (div:hover, a:hover)</li>
</ol>
Use pseudo-elements
<ol>
	<li>p::first-line</li>
	<li>p::first-letter</li>
</ol>
Use hierarchical notation
<ol>
	<li>X:nth-child(n)   -  eg. li:nth-child(100)</li>
	<li>X:nth-last-child(n)</li>
	<li>X:nth-of-type(n)</li>
	<li>X:nth-of-last-of-type(n)</li>
	<li>X:first-child</li>
	<li>X:last-child</li>
	<li>X:only-child</li>
	<li>X:first-of-type (eg. ul:first-of-type)</li>
	<li>X:only-of-type //no sibling from its parent container</li>
</ol>
[/box]

[box title="Absolute positioning inside relative positioning" color="#333333"]

Without a relative positioned direct parent, the absolutely positioned children elements are positioning themselves in relation to the <strong>body</strong> element instead of their <strong>direct</strong> parent.

Reference: <a href="http://css-tricks.com/absolute-positioning-inside-relative-positioning/">Absolute positing inside relative positioning</a>

[/box]

[box title="CSS positioning" color="#333333"]

<strong>The Box Model</strong>

To understand positioning in CSS you must first understand the box model. For display purposes, every element in a document is considered to be a rectangular box which has a content area surrounded by padding, a border and margins.

There are two basic types of boxes, <em>block</em> and <em>inline.</em>
<ul>
	<li>inline: follow the flow without add new line.</li>
	<li>block: always starts an new line before and after. (override via display: inline)</li>
</ul>
<strong>Default inline elements</strong>
<ul>
	<li>&#60;span&#62;, &#60;a&#62;, &#60;img&#62;, &#60;input&#62;</li>
</ul>
<strong>Default block element</strong>
<ul>
	<li>&#60;div&#62;, &#60;p&#62;, &#60;ul&#62;, &#60;li&#62;, &#60;table&#62;, &#60;pre&#62;, &#60;blockquote&#62;, &#60;form&#62;</li>
</ul>
<strong>Rules</strong>
<ol>
	<li>Block elements may contain both inline elements and other block elements, but inline elements may contain <em>only</em> other inline elements.</li>
	<li>CSS features a property called display, which allows you to change a block element into an inline one and vice versa.</li>
</ol>
&#160;

[/box]

[box title="Float" color="#333333"]

<strong>Float</strong>
<ul>
	<li>A common problem with float-based layouts is that the floats' container doesn't want to stretch up to accomodate the floats. To do that, you need:</li>
</ul>
<pre>div.container {
	border: 1px solid #000000;
<strong> overflow: hidden; width: 100%;</strong>
}

div.left {
	width: 45%;
	float: left;
}

div.right {
	width: 45%;
	float: right;
}</pre>
&#160;

[/box]]]></description>
			<content:encoded><![CDATA[<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">CSS Selector</div>
<div class="su-box-content">
<ol>
<li>*  //universal selector</li>
<li>#container *  //everything under #container element</li>
<li>X  //all elements according to their type like ul, a, li, etc</li>
<li>X:visited, X:link  //pseudo-class targeting &#8211; eg. input[type=radio]:checked</li>
<li>#X : id selector    //target single element</li>
<li>.X : class selector //target multiple elements</li>
<li>X Y: descendant selector //select only a set of elements under X</li>
<li>X &gt; Y  //only direct children Y of X</li>
<li>X + Y //first adjacent sibling selector: select only the Y that is preceded by X (eg. ul + p)</li>
<li>X ~ Y //all sibling selector</li>
<li>X[Y]  //attribute selector (select X if it has Y as attribute)</li>
<li>X[Y="Z"] //conditional attribute selector : exact</li>
<li>X[Y*="Z"] //conditional attribute selector: contains</li>
<li>X[Y^="Z"] //conditional attribute selector: begins with</li>
<li>X[Y$="Z"] //conditional attribute selector: end with</li>
<li>X[Y~="Z"] //target an attribute which has a spaced-separated list of values</li>
<li>X:not(selector)</li>
</ol>
<p>Use those tag to help you generated content around the selected elements</p>
<ol>
<li>X:after</li>
<li>X:before</li>
<li>X:hover (div:hover, a:hover)</li>
</ol>
<p>Use pseudo-elements</p>
<ol>
<li>p::first-line</li>
<li>p::first-letter</li>
</ol>
<p>Use hierarchical notation</p>
<ol>
<li>X:nth-child(n)   -  eg. li:nth-child(100)</li>
<li>X:nth-last-child(n)</li>
<li>X:nth-of-type(n)</li>
<li>X:nth-of-last-of-type(n)</li>
<li>X:first-child</li>
<li>X:last-child</li>
<li>X:only-child</li>
<li>X:first-of-type (eg. ul:first-of-type)</li>
<li>X:only-of-type //no sibling from its parent container</li>
</ol>
</div>
</div>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">Absolute positioning inside relative positioning</div>
<div class="su-box-content">
<p>Without a relative positioned direct parent, the absolutely positioned children elements are positioning themselves in relation to the <strong>body</strong> element instead of their <strong>direct</strong> parent.</p>
<p>Reference: <a href="http://css-tricks.com/absolute-positioning-inside-relative-positioning/">Absolute positing inside relative positioning</a></p>
</div>
</div>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">CSS positioning</div>
<div class="su-box-content">
<p><strong>The Box Model</strong></p>
<p>To understand positioning in CSS you must first understand the box model. For display purposes, every element in a document is considered to be a rectangular box which has a content area surrounded by padding, a border and margins.</p>
<p>There are two basic types of boxes, <em>block</em> and <em>inline.</em></p>
<ul>
<li>inline: follow the flow without add new line.</li>
<li>block: always starts an new line before and after. (override via display: inline)</li>
</ul>
<p><strong>Default inline elements</strong></p>
<ul>
<li>&lt;span&gt;, &lt;a&gt;, &lt;img&gt;, &lt;input&gt;</li>
</ul>
<p><strong>Default block element</strong></p>
<ul>
<li>&lt;div&gt;, &lt;p&gt;, &lt;ul&gt;, &lt;li&gt;, &lt;table&gt;, &lt;pre&gt;, &lt;blockquote&gt;, &lt;form&gt;</li>
</ul>
<p><strong>Rules</strong></p>
<ol>
<li>Block elements may contain both inline elements and other block elements, but inline elements may contain <em>only</em> other inline elements.</li>
<li>CSS features a property called display, which allows you to change a block element into an inline one and vice versa.</li>
</ol>
<p>&nbsp;</p>
</div>
</div>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">Float</div>
<div class="su-box-content">
<p><strong>Float</strong></p>
<ul>
<li>A common problem with float-based layouts is that the floats&#8217; container doesn&#8217;t want to stretch up to accomodate the floats. To do that, you need:</li>
</ul>
<p><pre><pre>div.container {
&nbsp;&nbsp;border: 1px solid #000000;
&lt;strong&gt; overflow: hidden; width: 100%;&lt;/strong&gt;
}

div.left {
&nbsp;&nbsp;width: 45%;
&nbsp;&nbsp;float: left;
}

div.right {
&nbsp;&nbsp;width: 45%;
&nbsp;&nbsp;float: right;
}</pre></pre><br />
&nbsp;</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/css-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set up Mac for local WordPress development</title>
		<link>http://www.solutionhacker.com/steps-to-set-up-local-development-environment-for-wordpress/</link>
		<comments>http://www.solutionhacker.com/steps-to-set-up-local-development-environment-for-wordpress/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 20:14:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Site Building]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=968</guid>
		<description><![CDATA[Recently, I have bought myself a theme and plugin and I would like to extend my christian website "<a href="http://christianrelive.com">christianrelive.com</a>".  To do that, I need to get my local dev environment ready (ie. Mac). At the beginning, I thought it is an easy task. But I did come across several issues that I would like to document them out for my peers who have the same need as me. Below are the steps I took to create a local env that allows me to run and debug my wordpress website locally.
<h2>Steps to follow</h2>
<h3>Download and install XAMPP</h3>
[box title="Create loopback domain name" color="#333333"]

sudo vi /etc/hosts and add the followings:

127.0.0.1       christianrelive.local

[/box]

[box title="Configure Apache" color="#333333"]

sudo vi /Applications/XAMPP/etc/httpd.conf and add the following lines:

NameVirtualHost *:80
&#60;VirtualHost *:80&#62;
ServerName http://christianrelive.local
DocumentRoot "/Users/rayhon/Sites/christianrelive.com"
&#60;Directory /Users/rayhon/Sites/christianrelive.com&#62;
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
&#60;/Directory&#62;
&#60;/VirtualHost&#62;

[/box]

[box title="Get your site configured locally" color="#333333"]
<ul>
	<li>Download Wordpress from Production and put it under ~/Sites/christianrelive.com</li>
	<li>Backup my production db (ie. mysql_db.sql)</li>
	<li>Set up my local db with the production data.</li>
</ul>
mysql&#62; create database relivedb;
mysql -u root relivedb &#60; mysql_db.sql
<ul>
	<li>Edit wp-config.php (change DB_HOST= 127.0.0.1 and DB_USER and DB_PASS accordingly)</li>
</ul>
update wp_options set option_value = 'http://christianrelive.local' where option_name = 'siteurl' or option_name = 'home';

NOTE: if you forget the update line above, your login will forward to your live site instead of local.

[/box]

Restart Apache from XAMPP control to take effect!
<h3>Debug the php code</h3>
I am using phpstorm 2 for the work and you may have your own IDE. But either one, you may need to enable xDebug in order to do step thru debugging. I use the links below to get this working.
<ol>
	<li>Download the xdebug.so from this <a href="http://code.activestate.com/komodo/remotedebugging/">link</a>.</li>
	<li>Following this <a href="http://andrewlocatelliwoodcock.com/2012/01/03/debugging-php-setting-up-xdebug-with-xampp-on-mac-osx/">post</a> to set it up.</li>
</ol>
[box title="Key steps" color="#333333"]

Move the xdebug.so to /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626

Edit /Applications/XAMPP/etc/php.ini and add the followings:

[xdebug]
zend_extension=”/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so”
xdebug.remote_enable=1

[/box]

Now I can run my phpstorm in debug mode pointing to the ~/Sites/christianrelive.com

Hope it is helpful]]></description>
			<content:encoded><![CDATA[<p>Recently, I have bought myself a theme and plugin and I would like to extend my christian website &#8220;<a href="http://christianrelive.com">christianrelive.com</a>&#8220;.  To do that, I need to get my local dev environment ready (ie. Mac). At the beginning, I thought it is an easy task. But I did come across several issues that I would like to document them out for my peers who have the same need as me. Below are the steps I took to create a local env that allows me to run and debug my wordpress website locally.</p>
<h2>Steps to follow</h2>
<h3>Download and install XAMPP</h3>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">Create loopback domain name</div>
<div class="su-box-content">
<p>sudo vi /etc/hosts and add the followings:</p>
<p>127.0.0.1       christianrelive.local</p>
</div>
</div>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">Configure Apache</div>
<div class="su-box-content">
<p>sudo vi /Applications/XAMPP/etc/httpd.conf and add the following lines:</p>
<p>NameVirtualHost *:80<br />
&lt;VirtualHost *:80&gt;<br />
ServerName http://christianrelive.local<br />
DocumentRoot &#8220;/Users/rayhon/Sites/christianrelive.com&#8221;<br />
&lt;Directory /Users/rayhon/Sites/christianrelive.com&gt;<br />
DirectoryIndex index.php<br />
AllowOverride All<br />
Order allow,deny<br />
Allow from all<br />
&lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</p>
</div>
</div>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">Get your site configured locally</div>
<div class="su-box-content">
<ul>
<li>Download WordPress from Production and put it under ~/Sites/christianrelive.com</li>
<li>Backup my production db (ie. mysql_db.sql)</li>
<li>Set up my local db with the production data.</li>
</ul>
<p>mysql&gt; create database relivedb;<br />
mysql -u root relivedb &lt; mysql_db.sql</p>
<ul>
<li>Edit wp-config.php (change DB_HOST= 127.0.0.1 and DB_USER and DB_PASS accordingly)</li>
</ul>
<p>update wp_options set option_value = &#8216;http://christianrelive.local&#8217; where option_name = &#8216;siteurl&#8217; or option_name = &#8216;home&#8217;;</p>
<p>NOTE: if you forget the update line above, your login will forward to your live site instead of local.</p>
</div>
</div>
<p>Restart Apache from XAMPP control to take effect!</p>
<h3>Debug the php code</h3>
<p>I am using phpstorm 2 for the work and you may have your own IDE. But either one, you may need to enable xDebug in order to do step thru debugging. I use the links below to get this working.</p>
<ol>
<li>Download the xdebug.so from this <a href="http://code.activestate.com/komodo/remotedebugging/">link</a>.</li>
<li>Following this <a href="http://andrewlocatelliwoodcock.com/2012/01/03/debugging-php-setting-up-xdebug-with-xampp-on-mac-osx/">post</a> to set it up.</li>
</ol>
<div class="su-box" style="border:1px solid #292929">
<div class="su-box-title" style="background-color:#333333;border-top:1px solid #adadad;text-shadow:1px 1px 0 #0f0f0f">Key steps</div>
<div class="su-box-content">
<p>Move the xdebug.so to /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626</p>
<p>Edit /Applications/XAMPP/etc/php.ini and add the followings:</p>
<p>[xdebug]<br />
zend_extension=”/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so”<br />
xdebug.remote_enable=1</p>
</div>
</div>
<p>Now I can run my phpstorm in debug mode pointing to the ~/Sites/christianrelive.com</p>
<p>Hope it is helpful</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/steps-to-set-up-local-development-environment-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Write JQuery Plugin &#8211; Part 2</title>
		<link>http://www.solutionhacker.com/how-to-write-jquery-plugin/</link>
		<comments>http://www.solutionhacker.com/how-to-write-jquery-plugin/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 21:10:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Site Building]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=945</guid>
		<description><![CDATA[After I understand the JQuery basic, the first thing I would like to learn is how to write a JQuery plugin as I have seen so much cool widgets are written in this style. I believe this will give me a ticket to get into this land. When I first looked at the code of a JQuery plugin, I am quite confused at its syntax. After I went through some articles, I eventually got some ideas how it works. So, my goal in this tutorial is to jump start  you on writing your first plugin. If not, at least I hope it will help you to peel off the syntax and get you right to the core of a plugin.

<!--more-->
<h2>JQuery Plugin Template</h2>
To read a plugin, you first need to understand its general structure. Here is the JQuery template you normally see.

[code lang="js"]
(function($) {
     // plugin definition
     $.fn.myplugin = function(options) {

        // build main options before element iteration
        var opts = $.extend({}, $.fn.myplugin.defaults, options);

        // iterate and reformat each matched element
        return this.each(function() {
          //CODE TO MANIPULATE EACH MATCHED ELEMENT
          ....
        });
    };

    //custom javascript functions in your plugins
    ...

})(jQuery);
[/code]

<strong>What is in this template?</strong>
<ul>
	<li>It defines the name of the plugin as "myplugin" and this plugin is written as function object with options as parameter to pass in.</li>
	<li>The .extend method provides you a way to define the default options in your plugin and a mechanism to override it.</li>
	<li>With this plugin included in your JQuery code, you now can do $(selector).myplugin(xxx). This will pass the matching element(s) one by one to the each() method in the plugin. And the magic normally happen in this method.</li>
</ul>
<h2>Write my first plugin to highlight my text</h2>
Below is a simple plugin that uses this structure:

[code lang="js"]
(function($) {
     // plugin definition
     $.fn.myplugin = function(options) {
        debug(this);
        // build main options before element iteration
        var opts = $.extend({}, $.fn.myplugin.defaults, options);
        // iterate and reformat each matched element
        return this.each(function() {
           $this = $(this);
           // build element specific options
           var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
           // update element styles
           $this.css({
              backgroundColor: o.background,
              color: o.foreground
           });
           var markup = $this.html();
           // call our format function
           markup = $.fn.myplugin.format(markup);
           $this.html(markup);
        });
    };

    // private function for debugging
    function debug($obj) {
       if (window.console &#38;&#38; window.console.log)
          window.console.log('myplugin selection count: ' + $obj.size());
    };

    // define and expose our public format function
    $.fn.myplugin.format = function(txt) {
       return '&#60;strong&#62;' + txt + '&#60;/strong&#62;';
    };

    // plugin defaults
    $.fn.myplugin.defaults = {
       foreground: 'red',
       background: 'yellow'
    };

})(jQuery);

[/code]

Once you define the plugin, lets see how we can override the default properties.

[code]
// override plugin default foreground color
$.fn.myplugin.defaults.foreground = 'blue';
// ...
// invoke plugin using new defaults
$('.myDiv').myplugin();
// ...
// override default by passing options to plugin method
$('#green').myplugin({
  foreground: 'green'
});
[/code]

This plugin has 2 additional methods, one is private and one is public. Public function has the format like: $.fn.myplugin.format = function(xxx){...}. The reason why we expose a function to public b/c it gives a way for users to override it. With this, users can extend the functionality of the plugin.
<br/>
<h2>Metadata Plugin</h2>
You may have noticed another thing in the plugin code. That is the ".meta".
[code lang="js"]
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
[/code]
Imagine that if you want the selected elements to be highlight in specific color. How can you do that with the control I showed you? It is simply impossible as what I have shown you so far is global options. Thanks that JQuery allows you to add metadata at the element level that can be used inside the each() method. The code above check if metadata plugin is installed. If yes, it will extract the metadata using $this.data() and have it overridden the default options. If no, it will just use the default options.
<br/>
[code lang="html"]
&#60;!--  markup  --&#62;
&#60;div class=&#34;abc { background: 'red', foreground: 'white' }&#34;&#62;
  Have a nice day!
&#60;/div&#62;
&#60;div class=&#34;abc { foreground: 'orange' }&#34;&#62;
  Have a nice day!
&#60;/div&#62;
&#60;div class=&#34;abc { background: 'green' }&#34;&#62;
  Have a nice day!
&#60;/div&#62;
[/code]
You can now do $(.abc).myplugin() in your JQuery code and have each div with class="abc" doing different color of highlight.
<br/>
<h2>Conclusion</h2>
So far so good? Most of content here I borrowed from <a href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern">here</a>. All I do here is to organize it and provide some of my own explanation. Now I think I am ready to look at some of the cool widgets. 

]]></description>
			<content:encoded><![CDATA[<p>After I understand the JQuery basic, the first thing I would like to learn is how to write a JQuery plugin as I have seen so much cool widgets are written in this style. I believe this will give me a ticket to get into this land. When I first looked at the code of a JQuery plugin, I am quite confused at its syntax. After I went through some articles, I eventually got some ideas how it works. So, my goal in this tutorial is to jump start  you on writing your first plugin. If not, at least I hope it will help you to peel off the syntax and get you right to the core of a plugin.</p>
<p><span id="more-945"></span></p>
<h2>JQuery Plugin Template</h2>
<p>To read a plugin, you first need to understand its general structure. Here is the JQuery template you normally see.</p>
<pre class="brush: jscript; title: ; notranslate">
(function($) {
     // plugin definition
     $.fn.myplugin = function(options) {

        // build main options before element iteration
        var opts = $.extend({}, $.fn.myplugin.defaults, options);

        // iterate and reformat each matched element
        return this.each(function() {
          //CODE TO MANIPULATE EACH MATCHED ELEMENT
          ....
        });
    };

    //custom javascript functions in your plugins
    ...

})(jQuery);
</pre>
<p><strong>What is in this template?</strong></p>
<ul>
<li>It defines the name of the plugin as &#8220;myplugin&#8221; and this plugin is written as function object with options as parameter to pass in.</li>
<li>The .extend method provides you a way to define the default options in your plugin and a mechanism to override it.</li>
<li>With this plugin included in your JQuery code, you now can do $(selector).myplugin(xxx). This will pass the matching element(s) one by one to the each() method in the plugin. And the magic normally happen in this method.</li>
</ul>
<h2>Write my first plugin to highlight my text</h2>
<p>Below is a simple plugin that uses this structure:</p>
<pre class="brush: jscript; title: ; notranslate">
(function($) {
     // plugin definition
     $.fn.myplugin = function(options) {
        debug(this);
        // build main options before element iteration
        var opts = $.extend({}, $.fn.myplugin.defaults, options);
        // iterate and reformat each matched element
        return this.each(function() {
           $this = $(this);
           // build element specific options
           var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
           // update element styles
           $this.css({
              backgroundColor: o.background,
              color: o.foreground
           });
           var markup = $this.html();
           // call our format function
           markup = $.fn.myplugin.format(markup);
           $this.html(markup);
        });
    };

    // private function for debugging
    function debug($obj) {
       if (window.console &amp;&amp; window.console.log)
          window.console.log('myplugin selection count: ' + $obj.size());
    };

    // define and expose our public format function
    $.fn.myplugin.format = function(txt) {
       return '&lt;strong&gt;' + txt + '&lt;/strong&gt;';
    };

    // plugin defaults
    $.fn.myplugin.defaults = {
       foreground: 'red',
       background: 'yellow'
    };

})(jQuery);
</pre>
<p>Once you define the plugin, lets see how we can override the default properties.</p>
<pre class="brush: plain; title: ; notranslate">
// override plugin default foreground color
$.fn.myplugin.defaults.foreground = 'blue';
// ...
// invoke plugin using new defaults
$('.myDiv').myplugin();
// ...
// override default by passing options to plugin method
$('#green').myplugin({
  foreground: 'green'
});
</pre>
<p>This plugin has 2 additional methods, one is private and one is public. Public function has the format like: $.fn.myplugin.format = function(xxx){&#8230;}. The reason why we expose a function to public b/c it gives a way for users to override it. With this, users can extend the functionality of the plugin.<br />
<br/></p>
<h2>Metadata Plugin</h2>
<p>You may have noticed another thing in the plugin code. That is the &#8220;.meta&#8221;.</p>
<pre class="brush: jscript; title: ; notranslate">
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
</pre>
<p>Imagine that if you want the selected elements to be highlight in specific color. How can you do that with the control I showed you? It is simply impossible as what I have shown you so far is global options. Thanks that JQuery allows you to add metadata at the element level that can be used inside the each() method. The code above check if metadata plugin is installed. If yes, it will extract the metadata using $this.data() and have it overridden the default options. If no, it will just use the default options.<br />
<br/></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!--  markup  --&gt;
&lt;div class=&quot;abc { background: 'red', foreground: 'white' }&quot;&gt;
  Have a nice day!
&lt;/div&gt;
&lt;div class=&quot;abc { foreground: 'orange' }&quot;&gt;
  Have a nice day!
&lt;/div&gt;
&lt;div class=&quot;abc { background: 'green' }&quot;&gt;
  Have a nice day!
&lt;/div&gt;
</pre>
<p>You can now do $(.abc).myplugin() in your JQuery code and have each div with class=&#8221;abc&#8221; doing different color of highlight.<br />
<br/></p>
<h2>Conclusion</h2>
<p>So far so good? Most of content here I borrowed from <a href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern">here</a>. All I do here is to organize it and provide some of my own explanation. Now I think I am ready to look at some of the cool widgets. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/how-to-write-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery Tutorial &#8211; Part 1</title>
		<link>http://www.solutionhacker.com/jquery-tutorial-part-1/</link>
		<comments>http://www.solutionhacker.com/jquery-tutorial-part-1/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 03:45:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Site Building]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=908</guid>
		<description><![CDATA[This tutorial covered the JQuery Basic. To me, the most important part of JQuery is its capability to locate "element(s)" on the web page and "manipulate" them on the fly in ease. The "elements" I referred here includes:
<ul>
	<li>HTML element</li>
	<li>HTML attribute</li>
	<li>CSS element</li>
</ul>
The manipulation part I mean here includes:
<ul>
	<li>Changing its content</li>
	<li>Tell the element to carry an action</li>
	<li>Capture its event and handle it</li>
</ul>
This technology really provides a clean way to glue Javascript, HTML and CSS together. So I decide to spend sometime to learn it. This post is just the note I captured after I had gone through several basic tutorials. I merely do my job to cut out the crap and focus on creating a reference page for my own usage.

<!--more-->
<h2>Get Started</h2>
Include the following javascript in your html header:

[code lang="js"]
&#60;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js&#34;&#62;&#60;/script&#62;
[/code]

The code below registers an anonymous function to the ready event from document. So, when the page is ready, this anonymous function will be invoked and in turn register another anonymous function to the button's click event to tell all "p" to hide if user click on it.

[code lang="js"]

&#60;script type=&#34;text/javascript&#34;&#62;
    $(document).ready(function(){
       $(&#34;button&#34;).click(function(){
          $(&#34;p&#34;).hide();
       });
    });
&#60;/script&#62;

//simplified version:
&#60;script type=&#34;text/javascript&#34;&#62;
$(function(){
    $(&#34;button&#34;).click(function(){
       $(&#34;p&#34;).hide();
    });
});
&#60;/script&#62;
[/code]
<h2>Select an element on the web page</h2>
<strong>Syntax: $(selector)</strong>
<h3>element selector</h3>
<ol>
	<li>$("p")  -  all &#60;p&#62; elements</li>
	<li>$(".test") - all elements with class = "test"</li>
	<li>$("#test") - all elements with id="test"</li>
	<li>$(this) - current element</li>
	<li>$("p.test") - all paragraph with class =" test"</li>
	<li>$("p#test") - all paragraph with id="test"</li>
	<li>$("p#intro:first) - the first &#60;p&#62; element with id="intro"</li>
	<li>$("div &#62; a") - all &#60;a&#62; elements directly under &#60;div&#62;</li>
	<li>$("div a") - all &#60;a&#62; within a div element, no matter directly under it or not.</li>
	<li>$("#divTestArea1 span, #divTestArea1 b") - multiple selectors</li>
</ol>
<h3>attribute selector</h3>
<ol>
	<li>$("[href]") - select all elements with an href attribute</li>
	<li>$("[href='#']") - select all element with an href value equals to #</li>
	<li>$("[href!='#']") - select all element with an href attribute NOT equals to #</li>
	<li>$("[href$='.jpg']") - select all element with an href attribute end with .jpg</li>
	<li>$("a[target='_blank']") - select &#60;a&#62; element with target attribute = "_blank"</li>
	<li>$("input[name^='txt']") -  start with "txt"</li>
	<li>$("input[name$='letter']") - end with "letter"</li>
	<li>$("input[name*='txt']") -  contain "txt"</li>
</ol>
<h3>Css selector</h3>
As best practice, you normally don't have style embedded with the html. If you want to selectively apply the style, you identify the element using id and/or class. So, you simply can use the element selector above.
<h2>Manipulate an element on the web page</h2>
<h3>Manipulate HTML element</h3>
[code lang="js"]
&#60;div id=&#34;divText&#34;&#62;&#60;/div&#62;
&#60;div id=&#34;divHtml&#34;&#62;&#60;/div&#62;
&#60;input type=&#34;text&#34; id=&#34;txtTest&#34; name=&#34;txtTest&#34; value=&#34;Input field&#34; /&#62;

&#60;script type=&#34;text/javascript&#34;&#62;
$(function()
{
     $(&#34;#divText&#34;).text(&#34;A dynamically set text&#34;);
     $(&#34;#divHtml&#34;).html(&#34;&#60;b&#62;&#60;i&#62;A dynamically set HTML string&#60;/i&#62;&#60;/b&#62;&#34;);
     $(&#34;#txtTest&#34;).val(&#34;A dynamically set value&#34;);
});

//NOTE: you can use callback here to capture the old value and element index
&#60;/script&#62;
[/code]

There are some other ways you can use to change the content of the element:
<ol>
	<li>$("p").html("xxxx");</li>
	<li>$("p").append("xxxx");</li>
	<li>$("p").before("xxx");</li>
	<li>$("p").after("xxxx");</li>
</ol>
<h3>Manipulate HTML attribute</h3>
[code lang="js"]

$(selector).attr(&#34;attributeName&#34;, &#34;attributeValue&#34;);

//multiple changes at one shot
$(&#34;#aGoogle3&#34;).attr(
{
    &#34;href&#34; : &#34;http://www.google.co.uk&#34;,
    &#34;title&#34; : &#34;Google.co.uk&#34;
});

//callback for you to obtain the old attribute value and element index
//example below appends new info in the url
$(&#34;a.google&#34;).attr(&#34;href&#34;, function(index, oldValue)
{
    return oldValue + &#34;imghp?tab=wi&#34;;
});

[/code]
<h3>Manipulate CSS properties</h3>
[code lang="js"]

$(&#34;p&#34;).css(&#34;background-color&#34;, &#34;yellow&#34;);   //change all paragraph's background color to yellow.
$(&#34;p&#34;).css({&#34;background-color&#34;:&#34;yellow&#34;, &#34;font-size&#34;:&#34;200%&#34;});    //multiple changes

&#60;script type=&#34;text/javascript&#34;&#62;
function ToggleClass(sender)
{
   if($(sender).hasClass(&#34;bold&#34;))
      $(sender).removeClass(&#34;bold&#34;);
   else
      $(sender).addClass(&#34;bold&#34;);
}
&#60;/script&#62;
&#60;a href=&#34;javascript:void(0);&#34; onclick=&#34;$(this).toggleClass('bold');&#34;&#62;Toggle class&#60;/a&#62;

[/code]
<h3>Tell an element to take an action</h3>
TODO
<h3>Capture the event from an element and handle it</h3>
[code lang="js"]
//typical way to do it, not clean at all
&#60;a href=&#34;javascript:void(0);&#34; onclick=&#34;alert('Hello, world!');&#34;&#62;Test&#60;/a&#62;

//use JQuery to bind the handler dynamically
&#60;script type=&#34;text/javascript&#34;&#62;
$(function()
{
        $(&#34;a&#34;).bind(&#34;click&#34;, function() {
             alert($(this).text());
        });
        $(&#34;#divArea&#34;).bind(&#34;mousemove&#34;, function(event)
        {
             $(this).text(event.pageX + &#34;,&#34; + event.pageY);
        });
});
&#60;/script&#62;
//javascript:void(0) simply disable sending users to another page
&#60;a href=&#34;javascript:void(0);&#34;&#62;Test 1&#60;/a&#62;
&#60;a href=&#34;javascript:void(0);&#34;&#62;Test 2&#60;/a&#62;
[/code]
<ol>
	<li>jQuery will automatically assign the element that is clicked, to the "this" keyword inside of the anonymous function.</li>
	<li>When jQuery calls your method, it will pass information about the event as the first parameter, if you have specified one or more parameters on it like the mouseover anonymous function above.</li>
	<li>You can use unbind() to remove any event handlers that you have attached with the bind() function</li>
	<li>bind will apply to the element already exists in the page. It will not apply to element that you dynamically added. To do that, you need to use live() instead. To unbind live, you need to use die().</li>
</ol>
[code lang="js"]
&#60;div id=&#34;divTestArea2&#34;&#62;
    &#60;a href=&#34;javascript:void(0);&#34; onclick=&#34;AddBox();&#34;&#62;Add box&#60;/a&#62;
    &#60;div&#62;This is a box&#60;/div&#62;
&#60;/div&#62;

&#60;script type=&#34;text/javascript&#34;&#62;
$(function()
{
    $(&#34;.test&#34;).live(&#34;mouseover&#34;, function(){
         $(this).css(&#34;background-color&#34;, &#34;blue&#34;);
    }).live(&#34;mouseout&#34;, function(){
        $(this).css(&#34;background-color&#34;, &#34;white&#34;);
    });
});

function AddBox()
{
    var div = $(&#34;&#60;div&#62;&#60;/div&#62;&#34;).addClass(&#34;test&#34;).text(&#34;Another box&#34;);
    $(&#34;#divTestArea2&#34;).append(div);
}
&#60;/script&#62;
[/code]

The example above shows you how to combine the things you have learnt:
<ol>
	<li>All JQuery methods return you JQuery object that you can use to chain them together if you want to apply several jquery methods to the selected element.</li>
	<li>It shows you have to dynamically create the &#60;div&#62; element and add class and value to it.</li>
	<li>It shows you how to append the newly created &#60;div&#62; to another element.</li>
	<li>It shows you how to use live to give the newly created the defined behavior rather than bind().</li>
</ol>
<h2>Conclusion</h2>
This conclude the first day of JQuery. So far, the tool is pretty cool to me. Later I will put sometime to learn about the topics below:
<ol>
	<li>JQuery and AJAX</li>
	<li>Write JQuery Plugin</li>
</ol>
After these, I will spend sometime to study some cool JQuery widgets and see how the author creates these. Below are some of the cool widget that I really want to dig into:
<ol>
	<li><a href="http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery">Simple Tooltip</a></li>
	<li><a href="utorialzine.com/2010/04/slideout-context-tips-jquery-css3/">Contextual Slideout tips</a></li>
	<li><a href="http://tympanus.net/codrops/2010/07/20/latest-tweets-tooltip/">Latest Tweet Tooltips</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This tutorial covered the JQuery Basic. To me, the most important part of JQuery is its capability to locate &#8220;element(s)&#8221; on the web page and &#8220;manipulate&#8221; them on the fly in ease. The &#8220;elements&#8221; I referred here includes:</p>
<ul>
<li>HTML element</li>
<li>HTML attribute</li>
<li>CSS element</li>
</ul>
<p>The manipulation part I mean here includes:</p>
<ul>
<li>Changing its content</li>
<li>Tell the element to carry an action</li>
<li>Capture its event and handle it</li>
</ul>
<p>This technology really provides a clean way to glue Javascript, HTML and CSS together. So I decide to spend sometime to learn it. This post is just the note I captured after I had gone through several basic tutorials. I merely do my job to cut out the crap and focus on creating a reference page for my own usage.</p>
<p><span id="more-908"></span></p>
<h2>Get Started</h2>
<p>Include the following javascript in your html header:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>The code below registers an anonymous function to the ready event from document. So, when the page is ready, this anonymous function will be invoked and in turn register another anonymous function to the button&#8217;s click event to tell all &#8220;p&#8221; to hide if user click on it.</p>
<pre class="brush: jscript; title: ; notranslate">

&lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function(){
       $(&quot;button&quot;).click(function(){
          $(&quot;p&quot;).hide();
       });
    });
&lt;/script&gt;

//simplified version:
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
    $(&quot;button&quot;).click(function(){
       $(&quot;p&quot;).hide();
    });
});
&lt;/script&gt;
</pre>
<h2>Select an element on the web page</h2>
<p><strong>Syntax: $(selector)</strong></p>
<h3>element selector</h3>
<ol>
<li>$(&#8220;p&#8221;)  -  all &lt;p&gt; elements</li>
<li>$(&#8220;.test&#8221;) &#8211; all elements with class = &#8220;test&#8221;</li>
<li>$(&#8220;#test&#8221;) &#8211; all elements with id=&#8221;test&#8221;</li>
<li>$(this) &#8211; current element</li>
<li>$(&#8220;p.test&#8221;) &#8211; all paragraph with class =&#8221; test&#8221;</li>
<li>$(&#8220;p#test&#8221;) &#8211; all paragraph with id=&#8221;test&#8221;</li>
<li>$(&#8220;p#intro:first) &#8211; the first &lt;p&gt; element with id=&#8221;intro&#8221;</li>
<li>$(&#8220;div &gt; a&#8221;) &#8211; all &lt;a&gt; elements directly under &lt;div&gt;</li>
<li>$(&#8220;div a&#8221;) &#8211; all &lt;a&gt; within a div element, no matter directly under it or not.</li>
<li>$(&#8220;#divTestArea1 span, #divTestArea1 b&#8221;) &#8211; multiple selectors</li>
</ol>
<h3>attribute selector</h3>
<ol>
<li>$(&#8220;[href]&#8220;) &#8211; select all elements with an href attribute</li>
<li>$(&#8220;[href='#']&#8220;) &#8211; select all element with an href value equals to #</li>
<li>$(&#8220;[href!='#']&#8220;) &#8211; select all element with an href attribute NOT equals to #</li>
<li>$(&#8220;[href$='.jpg']&#8220;) &#8211; select all element with an href attribute end with .jpg</li>
<li>$(&#8220;a[target='_blank']&#8220;) &#8211; select &lt;a&gt; element with target attribute = &#8220;_blank&#8221;</li>
<li>$(&#8220;input[name^='txt']&#8220;) -  start with &#8220;txt&#8221;</li>
<li>$(&#8220;input[name$='letter']&#8220;) &#8211; end with &#8220;letter&#8221;</li>
<li>$(&#8220;input[name*='txt']&#8220;) -  contain &#8220;txt&#8221;</li>
</ol>
<h3>Css selector</h3>
<p>As best practice, you normally don&#8217;t have style embedded with the html. If you want to selectively apply the style, you identify the element using id and/or class. So, you simply can use the element selector above.</p>
<h2>Manipulate an element on the web page</h2>
<h3>Manipulate HTML element</h3>
<pre class="brush: jscript; title: ; notranslate">
&lt;div id=&quot;divText&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;divHtml&quot;&gt;&lt;/div&gt;
&lt;input type=&quot;text&quot; id=&quot;txtTest&quot; name=&quot;txtTest&quot; value=&quot;Input field&quot; /&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
$(function()
{
     $(&quot;#divText&quot;).text(&quot;A dynamically set text&quot;);
     $(&quot;#divHtml&quot;).html(&quot;&lt;b&gt;&lt;i&gt;A dynamically set HTML string&lt;/i&gt;&lt;/b&gt;&quot;);
     $(&quot;#txtTest&quot;).val(&quot;A dynamically set value&quot;);
});

//NOTE: you can use callback here to capture the old value and element index
&lt;/script&gt;
</pre>
<p>There are some other ways you can use to change the content of the element:</p>
<ol>
<li>$(&#8220;p&#8221;).html(&#8220;xxxx&#8221;);</li>
<li>$(&#8220;p&#8221;).append(&#8220;xxxx&#8221;);</li>
<li>$(&#8220;p&#8221;).before(&#8220;xxx&#8221;);</li>
<li>$(&#8220;p&#8221;).after(&#8220;xxxx&#8221;);</li>
</ol>
<h3>Manipulate HTML attribute</h3>
<pre class="brush: jscript; title: ; notranslate">

$(selector).attr(&quot;attributeName&quot;, &quot;attributeValue&quot;);

//multiple changes at one shot
$(&quot;#aGoogle3&quot;).attr(
{
    &quot;href&quot; : &quot;http://www.google.co.uk&quot;,
    &quot;title&quot; : &quot;Google.co.uk&quot;
});

//callback for you to obtain the old attribute value and element index
//example below appends new info in the url
$(&quot;a.google&quot;).attr(&quot;href&quot;, function(index, oldValue)
{
    return oldValue + &quot;imghp?tab=wi&quot;;
});
</pre>
<h3>Manipulate CSS properties</h3>
<pre class="brush: jscript; title: ; notranslate">

$(&quot;p&quot;).css(&quot;background-color&quot;, &quot;yellow&quot;);   //change all paragraph's background color to yellow.
$(&quot;p&quot;).css({&quot;background-color&quot;:&quot;yellow&quot;, &quot;font-size&quot;:&quot;200%&quot;});    //multiple changes

&lt;script type=&quot;text/javascript&quot;&gt;
function ToggleClass(sender)
{
   if($(sender).hasClass(&quot;bold&quot;))
      $(sender).removeClass(&quot;bold&quot;);
   else
      $(sender).addClass(&quot;bold&quot;);
}
&lt;/script&gt;
&lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;$(this).toggleClass('bold');&quot;&gt;Toggle class&lt;/a&gt;
</pre>
<h3>Tell an element to take an action</h3>
<p>TODO</p>
<h3>Capture the event from an element and handle it</h3>
<pre class="brush: jscript; title: ; notranslate">
//typical way to do it, not clean at all
&lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;alert('Hello, world!');&quot;&gt;Test&lt;/a&gt;

//use JQuery to bind the handler dynamically
&lt;script type=&quot;text/javascript&quot;&gt;
$(function()
{
        $(&quot;a&quot;).bind(&quot;click&quot;, function() {
             alert($(this).text());
        });
        $(&quot;#divArea&quot;).bind(&quot;mousemove&quot;, function(event)
        {
             $(this).text(event.pageX + &quot;,&quot; + event.pageY);
        });
});
&lt;/script&gt;
//javascript:void(0) simply disable sending users to another page
&lt;a href=&quot;javascript:void(0);&quot;&gt;Test 1&lt;/a&gt;
&lt;a href=&quot;javascript:void(0);&quot;&gt;Test 2&lt;/a&gt;
</pre>
<ol>
<li>jQuery will automatically assign the element that is clicked, to the &#8220;this&#8221; keyword inside of the anonymous function.</li>
<li>When jQuery calls your method, it will pass information about the event as the first parameter, if you have specified one or more parameters on it like the mouseover anonymous function above.</li>
<li>You can use unbind() to remove any event handlers that you have attached with the bind() function</li>
<li>bind will apply to the element already exists in the page. It will not apply to element that you dynamically added. To do that, you need to use live() instead. To unbind live, you need to use die().</li>
</ol>
<pre class="brush: jscript; title: ; notranslate">
&lt;div id=&quot;divTestArea2&quot;&gt;
    &lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;AddBox();&quot;&gt;Add box&lt;/a&gt;
    &lt;div&gt;This is a box&lt;/div&gt;
&lt;/div&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
$(function()
{
    $(&quot;.test&quot;).live(&quot;mouseover&quot;, function(){
         $(this).css(&quot;background-color&quot;, &quot;blue&quot;);
    }).live(&quot;mouseout&quot;, function(){
        $(this).css(&quot;background-color&quot;, &quot;white&quot;);
    });
});

function AddBox()
{
    var div = $(&quot;&lt;div&gt;&lt;/div&gt;&quot;).addClass(&quot;test&quot;).text(&quot;Another box&quot;);
    $(&quot;#divTestArea2&quot;).append(div);
}
&lt;/script&gt;
</pre>
<p>The example above shows you how to combine the things you have learnt:</p>
<ol>
<li>All JQuery methods return you JQuery object that you can use to chain them together if you want to apply several jquery methods to the selected element.</li>
<li>It shows you have to dynamically create the &lt;div&gt; element and add class and value to it.</li>
<li>It shows you how to append the newly created &lt;div&gt; to another element.</li>
<li>It shows you how to use live to give the newly created the defined behavior rather than bind().</li>
</ol>
<h2>Conclusion</h2>
<p>This conclude the first day of JQuery. So far, the tool is pretty cool to me. Later I will put sometime to learn about the topics below:</p>
<ol>
<li>JQuery and AJAX</li>
<li>Write JQuery Plugin</li>
</ol>
<p>After these, I will spend sometime to study some cool JQuery widgets and see how the author creates these. Below are some of the cool widget that I really want to dig into:</p>
<ol>
<li><a href="http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery">Simple Tooltip</a></li>
<li><a href="utorialzine.com/2010/04/slideout-context-tips-jquery-css3/">Contextual Slideout tips</a></li>
<li><a href="http://tympanus.net/codrops/2010/07/20/latest-tweets-tooltip/">Latest Tweet Tooltips</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/jquery-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protected: Social Stuff</title>
		<link>http://www.solutionhacker.com/social-stuff/</link>
		<comments>http://www.solutionhacker.com/social-stuff/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 00:45:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Entrepreneur]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=892</guid>
		<description><![CDATA[There is no excerpt because this is a protected post.]]></description>
			<content:encoded><![CDATA[<form action="http://www.solutionhacker.com/wp-pass.php" method="post">
<p>This post is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-892">Password:<br />
<input name="post_password" id="pwbox-892" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Submit" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/social-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Power of WordPress Custom Field</title>
		<link>http://www.solutionhacker.com/power-of-wordpress-custom-field/</link>
		<comments>http://www.solutionhacker.com/power-of-wordpress-custom-field/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 08:14:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Build Money Site]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=835</guid>
		<description><![CDATA[<strong>Custom Fields</strong> are a form of <strong>meta-data</strong> that allows you to store arbitrary information with each WordPress post in <strong>key/value</strong> format. The key is the field name that stay the same for different posts whereas the value is the information that can change on each post and you can store more than one values for each key. Custom field information is stored in a table named "<strong>wp_postmeta</strong>" other than "<strong>wp_post</strong>" table. The schema of the wp_postmeta is quite generic so you can add as many custom fields as you want without changing the schema. This post is to show you some interesting ways I see how people use this metadata in their blogs.

<!--more-->
<h2>How to use the post metadata?</h2>
To use this metadata, you need to know how to pull them out. Below is what you can do:

[php]

//single value

&#60;?php echo get_post_meta($post-&#62;ID, 'key', true); ?&#62;

//multiple values
&#60;?php $songs = get_post_meta($post-&#62;ID, 'songs', false); ?&#62;
&#60;h3&#62;This post is inspired by:&#60;/h3&#62;
&#60;ul&#62;
  &#60;?php foreach($songs as $song) {
      echo '&#60;li&#62;'.$song.'&#60;/li&#62;';
    } ?&#62;
&#60;/ul&#62;
?&#62;
[/php]

Now you know how to get this metadata out from database. What can you do about this metadata? To get some ideas, you can look into a powerful plugins like <strong>Yoast’s WordPress SEO</strong>. It uses the custom fields to manage the html meta for SEO purpose. Many powerful frameworks like <strong>Genesis</strong>, <strong>Headway</strong>, <strong>iThemes</strong> are also utilizing custom fields to control different single post layouts. Here are other ideas:
<ul>
	<li>Only Display Posts with a Specific Custom Field</li>
	<li>Display the Digg Button only when the custom field is present</li>
	<li>Rewrite Guest Author’s name with Custom Fields (need add_filter)</li>
</ul>
[php]

add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );

function guest_author_name( $name ) {
   global $post;
   $author = get_post_meta( $post-&#62;ID, 'guest-author', true );
   if ( $author )
     $name = $author;
   return $name;
}

[/php]
<ul>
	<li>Custom sidebar. Replace "&#60;?php get_sidebar(); ?&#62;" in  page.php or single.php with the following code:</li>
</ul>
[php]
&#60;?php
global $wp_query;
$postid = $wp_query-&#62;post-&#62;ID;
$sidebar = get_post_meta($postid, &#34;sidebar&#34;, true);
get_sidebar($sidebar);
wp_reset_query();
?&#62;
[/php]
<h2>How to build a custom write panel?</h2>
In fact, there are more and more plugins and frameworks are using custom fields to extend the power of wordpress. Imagine if you need to use <strong>custom field panel</strong> in post to manage all those custom fields, you may spend days to write a post. So, many plugin and framework designers are now using <strong>custom write panel</strong> to hide this from us in order to make our lives easier.]]></description>
			<content:encoded><![CDATA[<p><strong>Custom Fields</strong> are a form of <strong>meta-data</strong> that allows you to store arbitrary information with each WordPress post in <strong>key/value</strong> format. The key is the field name that stay the same for different posts whereas the value is the information that can change on each post and you can store more than one values for each key. Custom field information is stored in a table named &#8220;<strong>wp_postmeta</strong>&#8221; other than &#8220;<strong>wp_post</strong>&#8221; table. The schema of the wp_postmeta is quite generic so you can add as many custom fields as you want without changing the schema. This post is to show you some interesting ways I see how people use this metadata in their blogs.</p>
<p><span id="more-835"></span></p>
<h2>How to use the post metadata?</h2>
<p>To use this metadata, you need to know how to pull them out. Below is what you can do:</p>
<pre class="brush: php; title: ; notranslate">

//single value

&lt;?php echo get_post_meta($post-&gt;ID, 'key', true); ?&gt;

//multiple values
&lt;?php $songs = get_post_meta($post-&gt;ID, 'songs', false); ?&gt;
&lt;h3&gt;This post is inspired by:&lt;/h3&gt;
&lt;ul&gt;
  &lt;?php foreach($songs as $song) {
      echo '&lt;li&gt;'.$song.'&lt;/li&gt;';
    } ?&gt;
&lt;/ul&gt;
?&gt;
</pre>
<p>Now you know how to get this metadata out from database. What can you do about this metadata? To get some ideas, you can look into a powerful plugins like <strong>Yoast’s WordPress SEO</strong>. It uses the custom fields to manage the html meta for SEO purpose. Many powerful frameworks like <strong>Genesis</strong>, <strong>Headway</strong>, <strong>iThemes</strong> are also utilizing custom fields to control different single post layouts. Here are other ideas:</p>
<ul>
<li>Only Display Posts with a Specific Custom Field</li>
<li>Display the Digg Button only when the custom field is present</li>
<li>Rewrite Guest Author’s name with Custom Fields (need add_filter)</li>
</ul>
<pre class="brush: php; title: ; notranslate">

add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );

function guest_author_name( $name ) {
   global $post;
   $author = get_post_meta( $post-&gt;ID, 'guest-author', true );
   if ( $author )
     $name = $author;
   return $name;
}
</pre>
<ul>
<li>Custom sidebar. Replace &#8220;&lt;?php get_sidebar(); ?&gt;&#8221; in  page.php or single.php with the following code:</li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
global $wp_query;
$postid = $wp_query-&gt;post-&gt;ID;
$sidebar = get_post_meta($postid, &quot;sidebar&quot;, true);
get_sidebar($sidebar);
wp_reset_query();
?&gt;
</pre>
<h2>How to build a custom write panel?</h2>
<p>In fact, there are more and more plugins and frameworks are using custom fields to extend the power of wordpress. Imagine if you need to use <strong>custom field panel</strong> in post to manage all those custom fields, you may spend days to write a post. So, many plugin and framework designers are now using <strong>custom write panel</strong> to hide this from us in order to make our lives easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/power-of-wordpress-custom-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mastering WordPress Shortcodes</title>
		<link>http://www.solutionhacker.com/mastering-wordpress-shortcode/</link>
		<comments>http://www.solutionhacker.com/mastering-wordpress-shortcode/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 05:53:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Build Money Site]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.solutionhacker.com/?p=627</guid>
		<description><![CDATA[I have used <strong> Wordpress </strong> to build my money site as many <strong> affiliate marketers </strong> suggested. However, this post is not going to show you how to set up a typical <strong> Wordpress Website </strong> . There are many tutorials online that show you how to do this in steps. So, I am not going to repeat it here. The only tip I suggest here is that if you want to have a professional looking website. You should really consider to spend a little money to purchase a <a href="http://www.elegantthemes.com/affiliates/idevaffiliate.php?id=11686"> professional and customizable theme from Elegantthemes.com </a> . Just paying around $30 bucks, you can have full access of tons of their professional themes. Since I have owned quite a number of websites, it is indeed a great deal for me. Anyway, as I said, it is not what I am going to talk about here today. Today, I would like to show you how <strong> wordpress shortcode </strong> works behind the scene.

<!--more-->
<h2>What is wordpress shortcodes?</h2>
The best way to show you the power of <strong> wordpress shortcode </strong> is to give you some examples.

[tabs style="default" title="Wordpress shortcode demo"]

[tab title="Amazon Product"]

[amazon asin="B0047DVWLW" template="Simple Ad Unit"]

[/tab]

[tab title="Price Change History"]

<strong> 3rd party new price </strong>

[rsstag url=http://camelcamelcamel.com/product/B0047DVWLW/new.xml]

<strong> 3rd party used price </strong>

[rsstag url=http://camelcamelcamel.com/product/B0047DVWLW/used.xml]

[/tab]

[tab title="Follow"][twitter_stream search="ipad 2"] [/tab]

[/tabs]

The widget above is created purely using wordpress shortcodes. See the code below:
<pre class="xml" title="code">[tabs style="default" title="Wordpress shortcode demo"]
   [tab title="Amazon Product"] [amazon asin="B0047DVWLW" template="Simple Ad Unit"][/tab]
   [tab title="Facebook Comments"]
      [rsstag url=http://camelcamelcamel.com/product/B0047DVWLW/new.xml]
      [rsstag url=http://camelcamelcamel.com/product/B0047DVWLW/used.xml]
   [/tab]
   [tab title="Follow"] [twitter_stream search="ipad 2"] [/tab]
[/tabs]</pre>
Isn't that cool? With few lines of xml like tag, I am able to create a widget that shows the product summary, its price history and who is following it. As you can see above, I have combined 4 different shortcodes from 4 different plugins into one widget. At the high level, there are 2 kinds of shortcodes: <strong> layout </strong> and <strong> content </strong> . <strong> Layout shortcodes </strong> are helping you to present the content in a nice looking way. <strong> Content shortcodes </strong> are to help you to pull the content from different sources in a simple way.
<h2>Shortcode in Template</h2>
If you are creating a product detail page, you can open your wordpress editor to type in the shortcode like above. However, if you have quit a bit of products, this process will be very tedious. If you are a tech person, you could create a script to load your products' content into wordpress database's post table. But if you want to use wordpress as the data entry UI, you can create a product detail template that leverages the shortcodes using the specific method below:

[php]
&#60;?php echo do_shortcode(&#34;[shortcode]&#34;); ?&#62;
[/php]

You can also use shortcode dynamically based on the custom field setting like below:

[php]
&#60;?php
if(get_post_meta($post-&#62;ID, 'gallery', true)) {
    $shortcode = get_post_meta($post-&#62;ID, 'gallery', true);
    echo do_shortcode(&#34;$shortcode&#34;);
 }
 else { echo ''; }
?&#62;
[/php]
<h2>How to create your own wordpress shortcodes?</h2>
There are times you cannot find any shortcode that fits your need exactly. Two things you can do:
<ol>
	<li>Customize an existing one from other plugin.</li>
	<li>Build one from scratch yourself.</li>
</ol>
However, both require you to have good understanding how shortcodes work behind the scene. Don't worry. It is not that difficult if you have a little bit of coding skill. To define your own wordpress shortcode, you first write a function of what you want the shortcode to do. Then you register the function via add_shortcode(tagName, functionName). Here is an example to define the shortcode name bartag with attribute foo. The extract method below taking the return of another function shortcode_atts that is used to define the default attribute value(s). If an attribute is not in this default list, it will not even be interpreted.

[php]
// [bartag foo=&#34;foo-value&#34;]
  function bartag_func( $atts ) {
     extract( shortcode_atts( array(
        'foo' =&#62; 'something',
        'bar' =&#62; 'something else',
     ), $atts ) );
    return &#34;foo = {$foo}&#34;;
  }
  add_shortcode( 'bartag', 'bartag_func' );
[/php]

Now you have an good idea how to define a function. Here we are going to create a shortcode to make Google chart creation easier (ie. no need to remember the parameters and url).

Creating a Google chart is quite simple, you just need to simply define a url under "img" will do the magic. However, the url uses some short parameters that you may need to look them up in order to create the url correctly. To make it easier, we create the shortcode above to make the parameters more explicit and hide the google url for you. With this shortcode, now you can create a sparkline chart as following.

[php]
function chart_shortcode( $atts ) {
   extract(shortcode_atts(array(
     'data' =&#62; '',
     'colors' =&#62; '',
     'size' =&#62; '400x200',
     'bg' =&#62; 'ffffff',
     'title' =&#62; '',
     'labels' =&#62; '',
     'advanced' =&#62; '',
     'type' =&#62; 'pie'
   ), $atts));

switch ($type) {
case 'line' :
   $charttype = 'lc'; break;
case 'xyline' :
   $charttype = 'lxy'; break;
case 'sparkline' :
   $charttype = 'ls'; break;
case 'meter' :
   $charttype = 'gom'; break;
case 'scatter' :
   $charttype = 's'; break;
case 'venn' :
   $charttype = 'v'; break;
case 'pie' :
   $charttype = 'p3'; break;
case 'pie2d' :
   $charttype = 'p'; break;
default :
   $charttype = $type;
break;
}

if ($title) $string .= '&#38;chtt='.$title.'';
if ($labels) $string .= '&#38;chl='.$labels.'';
if ($colors) $string .= '&#38;chco='.$colors.'';
$string .= '&#38;chs='.$size.'';
$string .= '&#38;chd=t:'.$data.'';
$string .= '&#38;chf='.$bg.'';

return '&#60;img title=&#34;'.$title.'&#34; src=&#34;http://chart.apis.google.com/chart?cht='.$charttype.''.$string.$advanced.'&#34; alt=&#34;'.$title.'&#34; /&#62;';
}
add_shortcode('chart', 'chart_shortcode');
[/php]

After you write this code, save it under plugin file named google-chart.php and put the following header above the function.

[php]

&#60;?php
/**
* @package Google Chart
* @version 1.0
*/
/*
Plugin Name: Google Chart Shortcode
Plugin URI:
Description: This is google chart shortcode plugin
Author: Raymond Hon
Version: 1.0
Author URI: http://www.solutionhacker.com
*/

...

&#60;/php&#62;

[/php]

Then you can activate this plugin in Wordpress. If it is activated, you can put the following wordpress shortcode in your post and generate the chart as below:
<p style="text-align: center;">[chart data="0,12,24,26,32,64,54,24,22,20,8,2,0,0,3" bg="F7F9FA" size="200x100" type="sparkline"]</p>
<p style="text-align: left;">[[chart data="0,12,24,26,32,64,54,24,22,20,8,2,0,0,3" bg="F7F9FA" size="200x100" type="sparkline"]]</p>

<h2 style="text-align: left;">When wordpress shortcode meets custom fields in post</h2>
Congratulation! If you follow my tutorial above, you have just equipped the key skill that can take your wordpress website to the next level.  However, I am not going to stop here. I would like to show you how you can use shortcode with custom field. First, you can write a shortcode to extract custom field value and use it in your post. To do that, you can build a plugin following the code below:

[php]
add_shortcode('field', 'shortcode_field');
function shortcode_field($atts){
     extract(shortcode_atts(array(
                  'post_id' =&#62; NULL,
               ), $atts));
  if(!isset($atts[0])) return;
       $field = esc_attr($atts[0]);
       global $post;
       $post_id = (NULL === $post_id) ? $post-&#62;ID : $post_id;
       return get_post_meta($post_id, $field, true);
}

[/php]

Once you can extract the custom field from post using shortcode, you can use it for UI and/ or post content.]]></description>
			<content:encoded><![CDATA[<p>I have used <strong> WordPress </strong> to build my money site as many <strong> affiliate marketers </strong> suggested. However, this post is not going to show you how to set up a typical <strong> WordPress Website </strong> . There are many tutorials online that show you how to do this in steps. So, I am not going to repeat it here. The only tip I suggest here is that if you want to have a professional looking website. You should really consider to spend a little money to purchase a <a href="http://www.elegantthemes.com/affiliates/idevaffiliate.php?id=11686"> professional and customizable theme from Elegantthemes.com </a> . Just paying around $30 bucks, you can have full access of tons of their professional themes. Since I have owned quite a number of websites, it is indeed a great deal for me. Anyway, as I said, it is not what I am going to talk about here today. Today, I would like to show you how <strong> wordpress shortcode </strong> works behind the scene.</p>
<p><span id="more-627"></span></p>
<h2>What is wordpress shortcodes?</h2>
<p>The best way to show you the power of <strong> wordpress shortcode </strong> is to give you some examples.</p>
<div class="su-tabs su-tabs-style-default">
<div class="su-tabs-nav"><span>Amazon Product</span><span>Price Change History</span><span>Follow</span></div>
<div class="su-tabs-panes">
<div class="su-tabs-pane">
<div style="text-align:center;">
<a href="http://www.amazon.com/Apple-MC979LL-Tablet-White-Generation/dp/B0047DVWLW%3FSubscriptionId%3DAKIAJLSJLJ5EKAQOAS5Q%26tag%3Dextremebuyer-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0047DVWLW">Apple iPad 2 MC979LL/A Tablet (16GB, Wifi, White) 2nd Generation</a><br />
<a href="http://www.amazon.com/Apple-MC979LL-Tablet-White-Generation/dp/B0047DVWLW%3FSubscriptionId%3DAKIAJLSJLJ5EKAQOAS5Q%26tag%3Dextremebuyer-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0047DVWLW"><img src="http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL160_.jpg" /></a><br />
$426.99
</div>
</div>
<div class="su-tabs-pane">
<p><strong> 3rd party new price </strong></p>
<ul>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 18, 2012 04:37 PM &#8211; $414.95</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 18, 2012 10:05 AM &#8211; $422.94</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 17, 2012 08:50 PM &#8211; $416.99</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 17, 2012 07:15 AM &#8211; $415.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 16, 2012 04:51 PM &#8211; $409.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 15, 2012 09:26 PM &#8211; $419.95</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 15, 2012 08:25 AM &#8211; $414.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 14, 2012 06:06 PM &#8211; $415.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 14, 2012 11:46 AM &#8211; $424.95</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_new' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 14, 2012 05:03 AM &#8211; $410.00</a></li>
</ul>
<p><strong> 3rd party used price </strong></p>
<ul>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 18, 2012 04:37 PM &#8211; $348.88</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 18, 2012 10:05 AM &#8211; $339.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 18, 2012 03:27 AM &#8211; $332.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 17, 2012 02:14 PM &#8211; $339.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 16, 2012 11:09 PM &#8211; $349.75</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 16, 2012 04:51 PM &#8211; $349.99</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 16, 2012 10:16 AM &#8211; $347.50</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 15, 2012 09:26 PM &#8211; $349.99</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 15, 2012 03:03 PM &#8211; $325.00</a></li>
<li><a class='rsswidget' href='http://camelcamelcamel.com/product/B0047DVWLW?active=price_used' title='Useful URLs: Amazon.com, camelcamelcamel.com [&hellip;]'>May 15, 2012 12:26 AM &#8211; $359.99</a></li>
</ul>
</div>
<div class="su-tabs-pane">
<ul class="tweet_list">
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/AlifAfganisme"><img src="http://a0.twimg.com/profile_images/2186657252/Posting_Iklan_for_Twitter_reasonably_small_normal.gif" alt="AlifAfganisme's avatar" title="AlifAfganisme's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/AlifAfganisme">AlifAfganisme</a> <span class="tweet_name">Alif Afganisme </span>
</div>
<div class="tweet_text">
	@<a href="http://twitter.com/sanditatto">sanditatto</a> Hello, follow @<a href="http://twitter.com/postingiklan">postingiklan</a> Tweet Iklan no.1 di Twitter,mau iPad 2 &amp; Samsung Android? Gampang! Cek fav.THX^^ <a href="http://search.twitter.com/search?q=&#038;tag=Periode8&#038;lang=all">#Periode8</a>
</div>
<div class="tweet_footer">
	19 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752966191185920">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752966191185920">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752966191185920">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/AlifAfganisme"><img src="http://a0.twimg.com/profile_images/2186657252/Posting_Iklan_for_Twitter_reasonably_small_normal.gif" alt="AlifAfganisme's avatar" title="AlifAfganisme's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/AlifAfganisme">AlifAfganisme</a> <span class="tweet_name">Alif Afganisme </span>
</div>
<div class="tweet_text">
	@<a href="http://twitter.com/ricogenji">ricogenji</a> Hello, follow @<a href="http://twitter.com/postingiklan">postingiklan</a> Tweet Iklan no.1 di Twitter,mau iPad 2 &amp; Samsung Android? Gampang! Cek fav.THX^^ <a href="http://search.twitter.com/search?q=&#038;tag=Periode8&#038;lang=all">#Periode8</a>
</div>
<div class="tweet_footer">
	23 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752948948414465">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752948948414465">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752948948414465">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/emdarlington"><img src="http://a0.twimg.com/profile_images/1617015459/z32_normal.jpg" alt="emdarlington's avatar" title="emdarlington's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/emdarlington">emdarlington</a> <span class="tweet_name">ellen darlington</span>
</div>
<div class="tweet_text">
	RT &amp; Follow the next big <a href="http://search.twitter.com/search?q=&#038;tag=college&#038;lang=all">#college</a> social network @<a href="http://twitter.com/freezecrowd">freezecrowd</a> to win an iPad 2 at 55,555 Join retweet list <a href="http://search.twitter.com/search?q=&#038;tag=sm&#038;lang=all">#sm</a> <a href="http://search.twitter.com/search?q=&#038;tag=smm&#038;lang=all">#smm</a>  <a href="http://t.co/JxEBzrtv">t.co/JxEBzrtv</a>
</div>
<div class="tweet_footer">
	25 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752943281905664">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752943281905664">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752943281905664">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/AlifAfganisme"><img src="http://a0.twimg.com/profile_images/2186657252/Posting_Iklan_for_Twitter_reasonably_small_normal.gif" alt="AlifAfganisme's avatar" title="AlifAfganisme's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/AlifAfganisme">AlifAfganisme</a> <span class="tweet_name">Alif Afganisme </span>
</div>
<div class="tweet_text">
	@<a href="http://twitter.com/Akafauri">Akafauri</a> Hello, follow @<a href="http://twitter.com/postingiklan">postingiklan</a> Tweet Iklan no.1 di Twitter,mau iPad 2 &amp; Samsung Android? Gampang! Cek fav.THX^^ <a href="http://search.twitter.com/search?q=&#038;tag=Periode8&#038;lang=all">#Periode8</a>
</div>
<div class="tweet_footer">
	27 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752932775182337">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752932775182337">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752932775182337">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/AlifAfganisme"><img src="http://a0.twimg.com/profile_images/2186657252/Posting_Iklan_for_Twitter_reasonably_small_normal.gif" alt="AlifAfganisme's avatar" title="AlifAfganisme's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/AlifAfganisme">AlifAfganisme</a> <span class="tweet_name">Alif Afganisme </span>
</div>
<div class="tweet_text">
	@<a href="http://twitter.com/bayuvirgian">bayuvirgian</a> Hello, follow @<a href="http://twitter.com/postingiklan">postingiklan</a> Tweet Iklan no.1 di Twitter,mau iPad 2 &amp; Samsung Android? Gampang! Cek fav.THX^^ <a href="http://search.twitter.com/search?q=&#038;tag=Periode8&#038;lang=all">#Periode8</a>
</div>
<div class="tweet_footer">
	31 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752916996206592">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752916996206592">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752916996206592">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/AlifAfganisme"><img src="http://a0.twimg.com/profile_images/2186657252/Posting_Iklan_for_Twitter_reasonably_small_normal.gif" alt="AlifAfganisme's avatar" title="AlifAfganisme's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/AlifAfganisme">AlifAfganisme</a> <span class="tweet_name">Alif Afganisme </span>
</div>
<div class="tweet_text">
	@<a href="http://twitter.com/IanTita_Item">IanTita_Item</a> Hello, follow @<a href="http://twitter.com/postingiklan">postingiklan</a> Tweet Iklan no.1 di Twitter,mau iPad 2 &amp; Samsung Android? Gampang! Cek fav.THX^^ <a href="http://search.twitter.com/search?q=&#038;tag=Periode8&#038;lang=all">#Periode8</a>
</div>
<div class="tweet_footer">
	36 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752894024003585">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752894024003585">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752894024003585">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/spoepona"><img src="http://a0.twimg.com/profile_images/2220980699/rsds_normal.png" alt="spoepona's avatar" title="spoepona's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/spoepona">spoepona</a> <span class="tweet_name">spoe pona</span>
</div>
<div class="tweet_text">
	10 ways Windows 8 tablets can take on the iPad  <a href="http://t.co/KrptWDeS">t.co/KrptWDeS</a> XPS 13 Motorola Motoluxe review Lumia 900 WP7 Xoom 2 tablet _1
</div>
<div class="tweet_footer">
	37 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752892828631041">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752892828631041">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752892828631041">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/swartling"><img src="http://a0.twimg.com/profile_images/1554898840/Stefan_Svartling_normal.JPG" alt="swartling's avatar" title="swartling's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/swartling">swartling</a> <span class="tweet_name">Stefan Svartling</span>
</div>
<div class="tweet_text">
	Kom igång med iPhoto till iOS med boken Hello iPhoto till iPad och iBooks 2  <a href="http://t.co/aLQoxHfx">t.co/aLQoxHfx</a> <a href="http://search.twitter.com/search?q=&#038;tag=Nyheter&#038;lang=all">#Nyheter</a>
</div>
<div class="tweet_footer">
	38 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752888294576128">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752888294576128">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752888294576128">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/1Matam"><img src="http://a0.twimg.com/sticky/default_profile_images/default_profile_6_normal.png" alt="1Matam's avatar" title="1Matam's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/1Matam">1Matam</a> <span class="tweet_name">matam honorine</span>
</div>
<div class="tweet_text">
	iPad 2 Sells for $100.03<br />
An iPad 2 Just Sold For $100.03 That&#8217;s 79% OFF the RETAIL Price! Visit  <a href="http://t.co/4rmzwSI9">t.co/4rmzwSI9</a> Now  Start Saving Today
</div>
<div class="tweet_footer">
	42 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752870019993601">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752870019993601">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752870019993601">favorite</a></span>
</div>
</div>
</li>
<li>
<div class="tweet">
<div class="tweet_avatar">
<a class="tweet_avatar" href="https://twitter.com/uqyfisiv"><img src="http://a0.twimg.com/profile_images/1994521290/643_normal.jpg" alt="uqyfisiv's avatar" title="uqyfisiv's avatar" border="0"/></a>
</div>
<div class="tweet_header">
	<a class="tweet_user" href="https://twitter.com/uqyfisiv">uqyfisiv</a> <span class="tweet_name">Raphael Vandervort</span>
</div>
<div class="tweet_text">
	Magenta Tri-PAD Canvas Case Stand for Apple iPad 2 + Black Car Charger for iPad 2 + Anti-Glare Screen Protector &#8230;  <a href="http://t.co/QnrRUdYO">t.co/QnrRUdYO</a>
</div>
<div class="tweet_footer">
	43 seconds ago <span class="tweet_footer_hidden"><a class="tweet_action tweet_reply" href="https://twitter.com/intent/tweet?in_reply_to=203752868170301440">reply</a> <a class="tweet_action tweet_retweet" href="https://twitter.com/intent/retweet?tweet_id=203752868170301440">retweet</a> <a class="tweet_action tweet_favorite" href="https://twitter.com/intent/favorite?tweet_id=203752868170301440">favorite</a></span>
</div>
</div>
</li>
</ul></div>
</div>
<div class="su-spacer"></div>
</div>
<p>The widget above is created purely using wordpress shortcodes. See the code below:<br />
<pre><pre class="xml" title="code">[tabs style=&quot;default&quot; title=&quot;Wordpress shortcode demo&quot;]
&nbsp;&nbsp; [tab title=&quot;Amazon Product&quot;] [amazon asin=&quot;B0047DVWLW&quot; template=&quot;Simple Ad Unit&quot;][/tab]
&nbsp;&nbsp; [tab title=&quot;Facebook Comments&quot;]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[rsstag url=http://camelcamelcamel.com/product/B0047DVWLW/new.xml]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[rsstag url=http://camelcamelcamel.com/product/B0047DVWLW/used.xml]
&nbsp;&nbsp; [/tab]
&nbsp;&nbsp; [tab title=&quot;Follow&quot;] [twitter_stream search=&quot;ipad 2&quot;] [/tab]
[/tabs]</pre></pre><br />
Isn&#8217;t that cool? With few lines of xml like tag, I am able to create a widget that shows the product summary, its price history and who is following it. As you can see above, I have combined 4 different shortcodes from 4 different plugins into one widget. At the high level, there are 2 kinds of shortcodes: <strong> layout </strong> and <strong> content </strong> . <strong> Layout shortcodes </strong> are helping you to present the content in a nice looking way. <strong> Content shortcodes </strong> are to help you to pull the content from different sources in a simple way.</p>
<h2>Shortcode in Template</h2>
<p>If you are creating a product detail page, you can open your wordpress editor to type in the shortcode like above. However, if you have quit a bit of products, this process will be very tedious. If you are a tech person, you could create a script to load your products&#8217; content into wordpress database&#8217;s post table. But if you want to use wordpress as the data entry UI, you can create a product detail template that leverages the shortcodes using the specific method below:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php echo do_shortcode(&quot;[shortcode]&quot;); ?&gt;
</pre>
<p>You can also use shortcode dynamically based on the custom field setting like below:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
if(get_post_meta($post-&gt;ID, 'gallery', true)) {
    $shortcode = get_post_meta($post-&gt;ID, 'gallery', true);
    echo do_shortcode(&quot;$shortcode&quot;);
 }
 else { echo ''; }
?&gt;
</pre>
<h2>How to create your own wordpress shortcodes?</h2>
<p>There are times you cannot find any shortcode that fits your need exactly. Two things you can do:</p>
<ol>
<li>Customize an existing one from other plugin.</li>
<li>Build one from scratch yourself.</li>
</ol>
<p>However, both require you to have good understanding how shortcodes work behind the scene. Don&#8217;t worry. It is not that difficult if you have a little bit of coding skill. To define your own wordpress shortcode, you first write a function of what you want the shortcode to do. Then you register the function via add_shortcode(tagName, functionName). Here is an example to define the shortcode name bartag with attribute foo. The extract method below taking the return of another function shortcode_atts that is used to define the default attribute value(s). If an attribute is not in this default list, it will not even be interpreted.</p>
<pre class="brush: php; title: ; notranslate">
// [bartag foo=&quot;foo-value&quot;]
  function bartag_func( $atts ) {
     extract( shortcode_atts( array(
        'foo' =&gt; 'something',
        'bar' =&gt; 'something else',
     ), $atts ) );
    return &quot;foo = {$foo}&quot;;
  }
  add_shortcode( 'bartag', 'bartag_func' );
</pre>
<p>Now you have an good idea how to define a function. Here we are going to create a shortcode to make Google chart creation easier (ie. no need to remember the parameters and url).</p>
<p>Creating a Google chart is quite simple, you just need to simply define a url under &#8220;img&#8221; will do the magic. However, the url uses some short parameters that you may need to look them up in order to create the url correctly. To make it easier, we create the shortcode above to make the parameters more explicit and hide the google url for you. With this shortcode, now you can create a sparkline chart as following.</p>
<pre class="brush: php; title: ; notranslate">
function chart_shortcode( $atts ) {
   extract(shortcode_atts(array(
     'data' =&gt; '',
     'colors' =&gt; '',
     'size' =&gt; '400x200',
     'bg' =&gt; 'ffffff',
     'title' =&gt; '',
     'labels' =&gt; '',
     'advanced' =&gt; '',
     'type' =&gt; 'pie'
   ), $atts));

switch ($type) {
case 'line' :
   $charttype = 'lc'; break;
case 'xyline' :
   $charttype = 'lxy'; break;
case 'sparkline' :
   $charttype = 'ls'; break;
case 'meter' :
   $charttype = 'gom'; break;
case 'scatter' :
   $charttype = 's'; break;
case 'venn' :
   $charttype = 'v'; break;
case 'pie' :
   $charttype = 'p3'; break;
case 'pie2d' :
   $charttype = 'p'; break;
default :
   $charttype = $type;
break;
}

if ($title) $string .= '&amp;chtt='.$title.'';
if ($labels) $string .= '&amp;chl='.$labels.'';
if ($colors) $string .= '&amp;chco='.$colors.'';
$string .= '&amp;chs='.$size.'';
$string .= '&amp;chd=t:'.$data.'';
$string .= '&amp;chf='.$bg.'';

return '&lt;img title=&quot;'.$title.'&quot; src=&quot;http://chart.apis.google.com/chart?cht='.$charttype.''.$string.$advanced.'&quot; alt=&quot;'.$title.'&quot; /&gt;';
}
add_shortcode('chart', 'chart_shortcode');
</pre>
<p>After you write this code, save it under plugin file named google-chart.php and put the following header above the function.</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php
/**
* @package Google Chart
* @version 1.0
*/
/*
Plugin Name: Google Chart Shortcode
Plugin URI:
Description: This is google chart shortcode plugin
Author: Raymond Hon
Version: 1.0
Author URI: http://www.solutionhacker.com
*/

...

&lt;/php&gt;
</pre>
<p>Then you can activate this plugin in WordPress. If it is activated, you can put the following wordpress shortcode in your post and generate the chart as below:</p>
<p style="text-align: center;">[chart data="0,12,24,26,32,64,54,24,22,20,8,2,0,0,3" bg="F7F9FA" size="200x100" type="sparkline"]</p>
<p style="text-align: left;">[[chart data="0,12,24,26,32,64,54,24,22,20,8,2,0,0,3" bg="F7F9FA" size="200x100" type="sparkline"]]</p>
<h2 style="text-align: left;">When wordpress shortcode meets custom fields in post</h2>
<p>Congratulation! If you follow my tutorial above, you have just equipped the key skill that can take your wordpress website to the next level.  However, I am not going to stop here. I would like to show you how you can use shortcode with custom field. First, you can write a shortcode to extract custom field value and use it in your post. To do that, you can build a plugin following the code below:</p>
<pre class="brush: php; title: ; notranslate">
add_shortcode('field', 'shortcode_field');
function shortcode_field($atts){
     extract(shortcode_atts(array(
                  'post_id' =&gt; NULL,
               ), $atts));
  if(!isset($atts[0])) return;
       $field = esc_attr($atts[0]);
       global $post;
       $post_id = (NULL === $post_id) ? $post-&gt;ID : $post_id;
       return get_post_meta($post_id, $field, true);
}
</pre>
<p>Once you can extract the custom field from post using shortcode, you can use it for UI and/ or post content.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.solutionhacker.com/mastering-wordpress-shortcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

