<?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>CMS tutorial site</title>
	<atom:link href="http://blog.cmstutorials.org/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.cmstutorials.org</link>
	<description>Free tutorials and resources</description>
	<lastBuildDate>Wed, 01 Feb 2012 09:27:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Featured tutorial of the week 01/02/2012</title>
		<link>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-01022012-2</link>
		<comments>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-01022012-2#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:27:54 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Round-Ups]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1552</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>This time you'll learn Node.js</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/this_time_you_ll_learn_node_js' target='_blank'>Title here</a></h3><a href='http://cmstutorials.org/tutorial/view/this_time_you_ll_learn_node_js' target='_blank'><img class='floatleft' src='http://cmstutorials.org/sources/tutorials/1326443448-tutimage-777.png' alt='Title here' title='Title here' /></a><p>In this series you will be using Node to create a simple blog engine to give you a real feel for how Node.js works.</p>
<a href='http://cmstutorials.org/tutorial/view/this_time_you_ll_learn_node_js'>View article</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-01022012-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create color pickers with frabtastic dynamicly</title>
		<link>http://blog.cmstutorials.org/freebees/how-to-create-color-pickers-with-frabtastic-dynamicly</link>
		<comments>http://blog.cmstutorials.org/freebees/how-to-create-color-pickers-with-frabtastic-dynamicly#comments</comments>
		<pubDate>Sat, 21 Jan 2012 17:07:55 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[Freebees]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[color picker]]></category>
		<category><![CDATA[frabtastic]]></category>
		<category><![CDATA[freebee]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1543</guid>
		<description><![CDATA[A very usefull code snippet to dynamicly create frabtastic color pickers for your Wordpress themes.]]></description>
			<content:encoded><![CDATA[<p>In a previous article (<a href="http://blog.cmstutorials.org/reviews/general/how-to-add-a-color-picker-in-your-wp-theme-using-frabtastic">How to add a color picker in your wp theme using frabtastic</a>) we explained how you could add color pickers using frabtastic in a custom WordPress admin panel for a specific theme. In this article we will provide you with an example on how you could extend this even further. So, instead of copy/pasting the code and markup for each color picker why not create the markup and code just once and reuse it for all other color pickers.</p>
<p>Enjoy this code and if you have any questions drop us a comment below. You can download the entire code as a <a href="http://blog.cmstutorials.org/wp-content/uploads/dynamic_frabtastic_color_pickers.zip">twentyten child theme</a>.</p>
<p>At the top of your functions.php add:</p>
<pre class="brush: php; title: ; notranslate">//define your color pickers
$colorPickers = array(
array('ID' =&gt; 'color_1', 'label' =&gt; 'Color 1', 'default_color' =&gt; '#002c84'),
array('ID' =&gt; 'color_2', 'label' =&gt; 'Color 2', 'default_color' =&gt; '#002c84'),
array('ID' =&gt; 'color_3', 'label' =&gt; 'Color 3', 'default_color' =&gt; '#002c84'),
array('ID' =&gt; 'color_4', 'label' =&gt; 'Color 4', 'default_color' =&gt; '#002c84'),
);</pre>
<p>The Markup:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
foreach($colorPickers as $colorPicker):
$colorOption = get_option($colorPicker['ID']);
if (empty($colorOption) || $colorOption == ''):
add_option($colorPicker['ID'], $colorPicker['default_color']);
endif;
?&gt;
&lt;div&gt;
&lt;label for=&quot;&lt;?php echo $colorPicker['ID']; ?&gt;&quot;&gt;&lt;?php _e($colorPicker['label']); ?&gt;&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;&lt;?php echo $colorPicker['ID']; ?&gt;&quot; value=&quot;&lt;?php echo get_option($colorPicker['ID']); ?&gt;&quot; name=&quot;&lt;?php echo $colorPicker['ID']; ?&gt;&quot; /&gt;
&lt;div id=&quot;&lt;?php echo $colorPicker['ID']; ?&gt;_color&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;?php endforeach; ?&gt;</pre>
<p>The jQuery:</p>
<pre class="brush: php; title: ; notranslate">var colorPickers = $('.color-picker');
for (e in colorPickers) {
if (colorPickers[e].id != undefined ) {
var colorPickerID = colorPickers[e].id;
$('#'+ colorPickerID + '_color').farbtastic('#' + colorPickerID);
}
}
</pre>
<p>The function to save it all in the DB:</p>
<pre class="brush: php; title: ; notranslate">function color_picker_option_update()
{
global $colorPickers;
foreach($colorPickers as $colorPicker) {
update_option($colorPicker['ID'], esc_html($_POST[$colorPicker['ID']]));
}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/freebees/how-to-create-color-pickers-with-frabtastic-dynamicly/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic website part 4 &#8211; Deleting records</title>
		<link>http://blog.cmstutorials.org/tutorials/dynamic-website-part-4-deleting-records</link>
		<comments>http://blog.cmstutorials.org/tutorials/dynamic-website-part-4-deleting-records#comments</comments>
		<pubDate>Sat, 07 Jan 2012 18:42:57 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[PHP & MYSQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[dynamic website]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1530</guid>
		<description><![CDATA[in part 4 of this tutorial serie we have a look on how to delete records from the database.]]></description>
			<content:encoded><![CDATA[<p>In the previous tutorials you learned how to read from the database and how to add new records. This time we will learn how to delete specific records.</p>
<p>First of all we will quickly add some links in the sidebar so we can navigate throught the pages more quickly.</p>
<pre class="brush: php; title: ; notranslate">
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;index.php&quot;&gt;Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;articles.php&quot;&gt;Articles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;addarticle.php&quot;&gt;Add article&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Now open the <strong>articles.php</strong> file. Under your article (within the while loop) add a delete link:</p>
<pre class="brush: php; title: ; notranslate">&lt;a href=&quot;&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;?action=delete&amp;article_id=&lt;?php echo  $row['id']; ?&gt;&quot;&gt;Delete&lt;/a&gt;</pre>
<p><a href="http://blog.cmstutorials.org/wp-content/uploads/add-delete-url.jpg" rel="lightbox[1530]" title="add-delete-url"><img class="alignnone size-full wp-image-1536" title="add-delete-url" src="http://blog.cmstutorials.org/wp-content/uploads/add-delete-url.jpg" alt="" /></a></p>
<p>Let&#8217;s go to the top of the page (but under the header include line) and catch our parameters. First we will see if there is a query parameter &#8216;action&#8217; and if it is the delete action. We also prepare our trycatchto check if an error occured.</p>
<pre class="brush: php; title: ; notranslate">
if(isset($_GET['action']) &amp;&amp; $_GET['action'] == 'delete')
{
	try{
		//check if an id was given and if it's a number
		//delete record
	}
	catch(Exception $e){
		echo '&lt;div class=&quot;feedback error&quot;&gt;' . $e-&gt;getMessage() . '&lt;/div&gt;';
	}
}
</pre>
<p>We first check for the id and make sure it is a number, if not we throw an exception. (place this in the trycatch)</p>
<pre class="brush: php; title: ; notranslate">
//if it does not exist
if(!isset($_GET['article_id']))
{
//throw an exception
	throw new exception('No id given');
}
//if it's a number
if(is_numeric($_GET['article_id'])){
	//store it in a variable
	$id = mysqli_real_escape_string($link, $_GET['article_id']);
} else {
	//else throw an exception
	throw new exception('The given id is not valid, only numbers!');
}
</pre>
<p>Now that we have the id of the article to delete we can create our query.</p>
<pre class="brush: php; title: ; notranslate">
if(!mysqli_query($link, 'DELETE FROM article WHERE id = ' . $id)){
	//if there was a problem executing the query throw an exception
	throw new exception('Could not delete record from the database');
} else {
	//display a success message
	echo '&lt;div class=&quot;feedback success&quot;&gt;Query successfully deleted.&lt;/div&gt;';
}
</pre>
<p>When you click the delete action you should now see a success message.<br />
<a href="http://blog.cmstutorials.org/wp-content/uploads/success_message.png" rel="lightbox[1530]" title="success_message"><img class="alignnone size-full wp-image-1537" title="success_message" src="http://blog.cmstutorials.org/wp-content/uploads/success_message.png" alt="" width="670" height="352" /></a></p>
<p>You can then add some styling for the error/success message</p>
<pre class="brush: css; title: ; notranslate">
/*ERROR MESSAGE*/
.error
{
padding: 8px 0px 8px 40px;
margin:5px 0px;
-moz-border-radius:4px;
border:1px solid #BF0008;
background:#FFDFDE url(&quot;../images/single_images/delete.png&quot;) no-repeat;
background-position:10px 10px;
color: #BF0008;
}

.error span
{
	font-weight:bold;
}

.error a:link, .error a:visited
{
color:#BF0008;
font-weight:bold;
text-decoration:underline;
}

.error a:hover, .error a:active
{
color:#FFF;
background:#BF0008;
font-weight:bold;
text-decoration:underline;
}

/*SUCCES MESSAGE*/
.succes
{
padding: 8px 0px 8px 40px;
margin:5px 0px;
-moz-border-radius:4px;
border:1px solid #057100;
background:#DFFFDE url(&quot;../images/single_images/check.png&quot;) no-repeat;
background-position:10px 10px;
color: #057100;
}

.succes span
{
	font-weight:bold;
}

.succes a:link, .succes a:visited
{
color:#057100;
font-weight:bold;
text-decoration:underline;
}

.succes a:hover, .succes a:active
{
color:#FFF;
background:#057100;
font-weight:bold;
text-decoration:underline;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/tutorials/dynamic-website-part-4-deleting-records/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Featured tutorial of the week 09/11/2011</title>
		<link>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-09112011</link>
		<comments>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-09112011#comments</comments>
		<pubDate>Wed, 09 Nov 2011 09:57:26 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Round-Ups]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[psd]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1516</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>From PSD to HTML: Building a Set of Website Designs Step by Step</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/from_psd_to_html_building_a_set_of_website_designs_step_by_step' target='_blank'>From PSD to HTML: Building a Set of Website Designs Step by Step</a></h3><a href='http://cmstutorials.org/tutorial/view/from_psd_to_html_building_a_set_of_website_designs_step_by_step' target='_blank'><img class='floatleft' src='http://blog.cmstutorials.org/wp-content/uploads/1319701828-tutimage-318.jpg' alt='From PSD to HTML: Building a Set of Website Designs Step by Step' title='From PSD to HTML: Building a Set of Website Designs Step by Step' /></a><p>This tutorial will take you through the entire process of converting a design in Photoshop to completed HTML template.</p>
<a href='http://cmstutorials.org/tutorial/view/from_psd_to_html_building_a_set_of_website_designs_step_by_step'>View tutorial</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-09112011/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Featured tutorial of the week 05/10/2011</title>
		<link>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-05102011</link>
		<comments>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-05102011#comments</comments>
		<pubDate>Wed, 05 Oct 2011 10:45:10 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Round-Ups]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[lookaheads]]></category>
		<category><![CDATA[lookbehinds]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tutorial of the week]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1508</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>How to use Lookaheads and Lookbehinds in your Regular Expressions</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/how_to_use_lookaheads_and_lookbehinds_in_your_regular_expressions' target='_blank'>How to use Lookaheads and Lookbehinds in your Regular Expressions</a></h3><a href='http://cmstutorials.org/tutorial/view/how_to_use_lookaheads_and_lookbehinds_in_your_regular_expressions' target='_blank'><img class='floatleft' src='http://cmstutorials.org/sources/tutorials/1317722561-tutimage-164.jpg' alt='How to use Lookaheads and Lookbehinds in your Regular Expressions' title='How to use Lookaheads and Lookbehinds in your Regular Expressions' /></a><p>This tutorial will teach you how to use positive &#038; negative lookahead and lookbehinds in your regular expressions.</p>
<a href='http://cmstutorials.org/tutorial/view/how_to_use_lookaheads_and_lookbehinds_in_your_regular_expressions'>View tutorial</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-05102011/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Featured tutorial of the week 38/08/2011</title>
		<link>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-38082011</link>
		<comments>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-38082011#comments</comments>
		<pubDate>Thu, 01 Sep 2011 08:00:26 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Round-Ups]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[queries]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1502</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>Advanced WordPress Queries, Part 1</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/advanced_wordpress_queries_part_1' target='_blank'>Advanced WordPress Queries, Part 1</a></h3><a href='http://cmstutorials.org/tutorial/view/advanced_wordpress_queries_part_1' target='_blank'><img class='floatleft' src='http://blog.cmstutorials.org/wp-content/uploads/figure_1.png' alt='Advanced WordPress Queries, Part 1' title='Advanced WordPress Queries, Part 1' /></a><p>Throughout this series, we’re going to take a look at the advantages of advanced queries, how we interface with the WordPress database, and how we can retrieve, update, and insert new and existing data.</p>
<a href='http://cmstutorials.org/tutorial/view/advanced_wordpress_queries_part_1'>View tutorial</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-38082011/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Featured tutorial of the week 13/08/2011</title>
		<link>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-13082011</link>
		<comments>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-13082011#comments</comments>
		<pubDate>Sat, 13 Aug 2011 08:26:50 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Round-Ups]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1499</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>A Beginner’s Guide to the WordPress Loop</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/a_beginner_s_guide_to_the_wordpress_loop' target='_blank'>A Beginner’s Guide to the WordPress Loop</a></h3><a href='http://cmstutorials.org/tutorial/view/a_beginner_s_guide_to_the_wordpress_loop' target='_blank'><img class='floatleft' src='' alt='A Beginner’s Guide to the WordPress Loop' title='A Beginner’s Guide to the WordPress Loop' /></a><p>Today, we’re going to lay a foundation for everyone who’s new to the loop or has ever wanted to know a little bit more about exactly how it works.</p>
<a href='http://cmstutorials.org/tutorial/view/a_beginner_s_guide_to_the_wordpress_loop'>View tutorial</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/other/featured-tutorial-of-the-week-13082011/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Featured tutorial of the week 04/08/2011</title>
		<link>http://blog.cmstutorials.org/reviews/general/featured-tutorial-of-the-week-04082011</link>
		<comments>http://blog.cmstutorials.org/reviews/general/featured-tutorial-of-the-week-04082011#comments</comments>
		<pubDate>Fri, 05 Aug 2011 09:00:41 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[uploading]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1491</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>Uploading Files with AJAX</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/uploading_files_with_ajax' target='_blank'>Uploading Files with AJAX</a></h3><a href='http://cmstutorials.org/tutorial/view/uploading_files_with_ajax' target='_blank'><img class='floatleft' src='http://blog.cmstutorials.org/wp-content/uploads/form.png' alt='Uploading Files with AJAX' title='Uploading Files with AJAX' /></a><p>Today, I’m going to show you how to do something that—until the last while—has been almost unprecedented: uploading files via AJAX.</p>
<a href='http://cmstutorials.org/tutorial/view/uploading_files_with_ajax'>View tutorial</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/reviews/general/featured-tutorial-of-the-week-04082011/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add a color picker in your wp theme using frabtastic</title>
		<link>http://blog.cmstutorials.org/reviews/general/how-to-add-a-color-picker-in-your-wp-theme-using-frabtastic</link>
		<comments>http://blog.cmstutorials.org/reviews/general/how-to-add-a-color-picker-in-your-wp-theme-using-frabtastic#comments</comments>
		<pubDate>Fri, 22 Jul 2011 20:27:32 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[color picker]]></category>
		<category><![CDATA[panel]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1472</guid>
		<description><![CDATA[In this tutorial I will teach you how to add a color picker in the option page of your wordpress theme using the build in frabtastic library.]]></description>
			<content:encoded><![CDATA[<p>Previously I wrote a tutorial on how to add a color picker to your admin theme page. I therefore choose a specific library which I used to create these color pickers. That was before I actually found that wordpress already includes a javascript library to create color pickers. In this quick tutorial I will teach you how to use it.</p>
<div class="info">You can download the result of this tutorial as a <a href="http://blog.cmstutorials.org/wp-content/uploads/color_picker_twentyten-child.zip">twentyten child theme</a></div>
<h2>A brief word about wp_enqueue_script()</h2>
<p>I actually found this when looking at the <code>wp_enqueue_script();</code> in the wordpress codex. When I scrolled down I saw an entire list of javascript libraries that are already present in wordpress, which you could then easily load using the <code>wp_enqueue_script();</code>. I strongly advice you have a look at <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Default_scripts_included_with_WordPress">all the libraries you can include</a>. And who knows, just like me, you might find out you are including a javascript or jQuery library that is already present in wordpress.</p>
<h2>Before getting started</h2>
<p>Before we start let&#8217;s add a simple link into the theme menu block in the admin area which links to a page which will contain the color picker. Just add the following code in the <code>functions.php</code> of your theme:</p>
<pre class="brush: php; title: ; notranslate">add_action('admin_menu', 'themeoptions_admin_menu'); //action to display the menu
function themeoptions_admin_menu()
{
add_theme_page('color picker', 'color picker', 'read', 'color_picker_option', 'color_picker_option_page');
}
function color_picker_option_page()
{

}</pre>
<p><code>color_picker_option_page()</code> is the function we specified to show the color pickers.</p>
<h2>Add the color picker</h2>
<p>First of all we need to load the farbtastic javascript library and style. Add the following code to your <code>functions.php</code> of your theme:</p>
<pre class="brush: php; title: ; notranslate">add_action('init', 'load_theme_scripts');
function load_theme_scripts() {
    wp_enqueue_style( 'farbtastic' );
    wp_enqueue_script( 'farbtastic' );
}</pre>
<p>We then add a simple form in our <code>color_picker_option_page()</code> function:</p>
<pre class="brush: php; title: ; notranslate">&lt;form method=&quot;POST&quot; action=&quot;&quot;&gt;
     &lt;input type=&quot;text&quot; id=&quot;color1&quot; value=&quot;&lt;?php echo get_option('color1'); ?&gt;&quot; name=&quot;color_picker_color1&quot; /&gt;
     &lt;div id=&quot;color_picker_color1&quot;&gt;&lt;/div&gt;
     &lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;update_options&quot; value=&quot;Update Options&quot; /&gt;&lt;/p&gt;
&lt;/form&gt;</pre>
<p>Now all that remains is to call the frabtastic function and specify where the color picker should be loaded and which input field will be used to dynamicly update the color value once you select another color. Add the following code in the <code>color_picker_option_page()</code> :</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;
        jQuery(document).ready(function($){
            $('#color_picker_color1').farbtastic('#color1');            
        });
    &lt;/script&gt;</pre>
<p>You should now have a working color picker:</p>
<p><img class="alignnone size-full wp-image-1478" title="color_picer_preview" src="http://blog.cmstutorials.org/wp-content/uploads/color_picer_preview.png" alt="" width="422" height="226" /></p>
<h2>Saving the color</h2>
<p>The last thing to do is to store the color value in a wordpress option. At the top of the <code>color_picker_option_page()</code> function add:</p>
<pre class="brush: php; title: ; notranslate">if ( isset($_POST['update_options'])) { color_picker_option_update(); }</pre>
<p>So when the form is submitted the <code>color_picker_option_update()</code> function will be called. So let&#8217;s create that function and save the color value:</p>
<pre class="brush: php; title: ; notranslate">function color_picker_option_update()
{
update_option('color1', esc_html($_POST['color_picker_color1']));
}</pre>
<p>So we get the color value using $_POST and we filter it using <code>esc_html()</code> (always filter submitted data!!) and finally it is saved. Update_option() will create the new option if it doesn&#8217;t exist yet.</p>
<h2>Adding a second color picker</h2>
<p>First of all copy/paste a second row for the second color picker</p>
<pre class="brush: php; title: ; notranslate">&lt;tr valign=&quot;top&quot;&gt;
	&lt;th width=&quot;200px&quot; scope=&quot;row&quot;&gt;Color 2&lt;/th&gt;
	&lt;td&gt;
		&lt;input type=&quot;text&quot; id=&quot;color2&quot; value=&quot;&lt;?php echo get_option('color2'); ?&gt;&quot; name=&quot;color_picker_color2&quot; /&gt;
		&lt;div id=&quot;color_picker_color2&quot;&gt;&lt;/div&gt;
	&lt;/td&gt;
&lt;/tr&gt;</pre>
<p>Add a second call to the farbtastic plugin</p>
<pre class="brush: php; title: ; notranslate">$('#color_picker_color2').farbtastic('#color2');</pre>
<p>Finally save the new color picker value in the update functions using the <code>update_option()</code> function</p>
<pre class="brush: php; title: ; notranslate">update_option('color2', esc_html($_POST['color_picker_color2']));</pre>
<p>The see the final code download the twentyeleven child theme at the top of this article.</p>
<h2>That&#8217;s it!</h2>
<p>So that&#8217;s all there is to do. Pretty easy, no? Much easier and faster than using jPicker which I introduced in my previous tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/reviews/general/how-to-add-a-color-picker-in-your-wp-theme-using-frabtastic/feed</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Featured tutorial of the week 20/07/2011</title>
		<link>http://blog.cmstutorials.org/reviews/general/featured-tutorial-of-the-week-20072011</link>
		<comments>http://blog.cmstutorials.org/reviews/general/featured-tutorial-of-the-week-20072011#comments</comments>
		<pubDate>Wed, 20 Jul 2011 08:00:04 +0000</pubDate>
		<dc:creator>krike</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[dreamweaver]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[fireworks]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.cmstutorials.org/?p=1466</guid>
		<description><![CDATA[Each week we feature a new tutorial. This weeks featured tutorial is <strong>How to Use CSS Sprites in Fireworks and Dreamweaver</strong>]]></description>
			<content:encoded><![CDATA[<div class='roundup_post'>
<h3><a href='http://cmstutorials.org/tutorial/view/how_to_use_css_sprites_in_fireworks_and_dreamweaver' target='_blank'>How to Use CSS Sprites in Fireworks and Dreamweaver</a></h3><a href='http://cmstutorials.org/tutorial/view/how_to_use_css_sprites_in_fireworks_and_dreamweaver' target='_blank'><img class='floatleft' src='http://blog.cmstutorials.org/wp-content/uploads/css_sprites_01-e1311019220585.png' alt='How to Use CSS Sprites in Fireworks and Dreamweaver' title='How to Use CSS Sprites in Fireworks and Dreamweaver' /></a><p>Ever wondered how to use CSS Sprites in your own web projects? In this tutorial Tom Green is going to walk through how to create CSS sprites in Fireworks and then put them to use in Dreamweaver.</p>
<a href='http://cmstutorials.org/tutorial/view/how_to_use_css_sprites_in_fireworks_and_dreamweaver'>View tutorial</a>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cmstutorials.org/reviews/general/featured-tutorial-of-the-week-20072011/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.924 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-01 10:44:39 -->

