<?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"
	>

<channel>
	<title>Developer Tutorials' Webmaster Blog &#187; PHP</title>
	<atom:link href="http://www.developertutorials.com/blog/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.developertutorials.com/blog</link>
	<description>Keeping webmasters up-to-date on technology.</description>
	<pubDate>Fri, 16 May 2008 04:17:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Running PHP cron jobs - regular scheduled tasks in PHP</title>
		<link>http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/</link>
		<comments>http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/#comments</comments>
		<pubDate>Thu, 15 May 2008 13:18:50 +0000</pubDate>
		<dc:creator>Akash Mehta</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/</guid>
		<description><![CDATA[Scheduled tasks are a fairly common feature in modern web applications. From cleaning out caches every 24 hours to checking subscription periods and even generating reports, more web applications live by the clock than ever before. But how do we schedule the execution of a PHP script on the server side?
The answer, for Linux-based servers, [...]]]></description>
			<content:encoded><![CDATA[<p>Scheduled tasks are a fairly common feature in modern web applications. From cleaning out caches every 24 hours to checking subscription periods and even generating reports, more web applications live by the clock than ever before. But how do we schedule the execution of a PHP script on the server side?</p>
<p>The answer, for Linux-based servers, is crontab. The crontab utility on UNIX systems allows commands to be executed and predefined intervals. These commands are essentially the same commands as you would run from any local console. For example, you could create a new cron &#8220;job&#8221; to run a bash script, and set it to run once per day at 12:00 midnight.</p>
<p><span id="more-172"></span></p>
<p>In terms of PHP, we can then call our PHP scripts via command line using the `php` binary. There are two issues here: first, we need to know where PHP is, and second, we need to know where our scripts are. Say your scripts are in /home/username/example.com, and your PHP binary is in /usr/bin, Your command to run your script could be this:</p>
<blockquote><p><code>/usr/bin/php /home/username/example.com/myscript.php</code></p>
</blockquote>
<p>Now, we have to configure cron to execute this. If your host has cPanel, you may have a cron job interface which will take this command as an option and allow you to configure visually the times at which it will execute. If you don&#8217;t have some kind of web-based interface, you&#8217;ll need to go one step further and manually create crontab entries via a command line terminal.</p>
<p>Fire up a console window at your server (e.g. in PuTTY) and run &#8220;crontab -e&#8221;. If you are prompted for an email address, enter an address you can easily manage e.g. a gmail inbox or a catch-all. A command-line text editor such as nano or vi/emacs should appear, and you&#8217;re ready to start creating crontab entries.</p>
<p>Here&#8217;s a sample entry:</p>
<blockquote><p><code>0 0 * * * /usr/bin/php /home/username/myscript.php</code></p>
</blockquote>
<p>The first section is the key: this defines the timing. There are five fields, minute, hour, day of month, month and day of week. Each takes a numerical value (typically starting at 0, not 1) or an asterisk to represent &#8220;all values&#8221;. Ranges are also an option, e.g. 1-5. For example, here we want the 0th minute of the 0th hour of every day of month, every month, on every day of week - in otherwords, midnight every day. <a href="http://www.adminschoice.com/docs/crontab.htm" target="_blank">This page</a> has a great tutorial on cron scheduling.</p>
<p>Once you&#8217;ve worked out the cron entry for your intended timing, just add the entry to your crontab file - edited by running `crontab -e` - and save and exit. Crontab will automatically manage the changes and start scheduling your tasks immediately. If your scripts have any output, you will also receive an email with the output. Practise this a little, and within no time you&#8217;ll be a PHP task scheduling master!</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d172').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d172" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/&amp;title=Running+PHP+cron+jobs+-+regular+scheduled+tasks+in+PHP" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/&amp;title=Running+PHP+cron+jobs+-+regular+scheduled+tasks+in+PHP" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/&amp;title=Running+PHP+cron+jobs+-+regular+scheduled+tasks+in+PHP" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/&amp;title=Running+PHP+cron+jobs+-+regular+scheduled+tasks+in+PHP" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d172').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/running-php-cron-jobs-regular-scheduled-tasks-in-php-172/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Testing PHP with the interactive shell</title>
		<link>http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/</link>
		<comments>http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/#comments</comments>
		<pubDate>Sat, 10 May 2008 02:18:22 +0000</pubDate>
		<dc:creator>Akash Mehta</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/</guid>
		<description><![CDATA[When it comes to trying out a snippet of PHP, the process can often be time consuming and tedious. Loading up your editor, saving a new file in your http docs folder, firing up a webserver, running some tests and then clearing the files off - it&#8217;s generally more trouble than its worth. Thankfully, PHP [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to trying out a snippet of PHP, the process can often be time consuming and tedious. Loading up your editor, saving a new file in your http docs folder, firing up a webserver, running some tests and then clearing the files off - it&#8217;s generally more trouble than its worth. Thankfully, PHP provides the interactive shell, allowing you to test out PHP interactively with immediate feedback. Here&#8217;s how to take advantage of this mature feature of PHP.<span id="more-168"></span></p>
<p>Make sure the folder with your PHP interpreter (where php.exe or the compiled php binary is stored) is in your system&#8217;s PATH. Here are some instructions <a href="http://www.troubleshooters.com/linux/prepostpath.htm" target="_blank">for linux</a> and <a href="http://www.computerhope.com/issues/ch000549.htm" target="_blank">windows</a>. You can test that PHP is in your path by firing up a command prompt / console window and running &#8220;php -v&#8221;. You should see your PHP version.</p>
<p>Provided you have a reasonably recent version of PHP (any version of PHP 5 is sufficient), you&#8217;re now all set to use PHP interactive mode! Open up a command prompt / console window and run &#8220;php -a&#8221;. You will see a message saying &#8220;Interactive mode enabled.&#8221; Next, type out a PHP open tag - <?php - and hit enter. You're now working with PHP interactively. Type out a line of code - e.g. $somevar = "blah"; - and hit enter. Nothing will happen - because it wouldn't in a standard PHP script. Now type out another line of code, echo ($somevar); - PHP will give you the value of $somevar, outputting "blah" on the newline.</p>
<p>There are a few quirks to remember when working with interactive mode.</p>
<p>First, avoid jumping in and out of code blocks. When you close a PHP block, type out some text and open another PHP block, PHP will output everything between the last close and open tag.</p>
<p>Your statements can span multiple lines - but remember to put in the closing semicolon. This might be obvious in an IDE, but it&#8217;s a common mistake in a simple terminal.</p>
<p>If something isn&#8217;t working quite right, debug your variables with echo calls - that&#8217;s what the interactive shell is for.</p>
<p>Watch your current directory. You may find the __FILE__ magic constant useful. If you want to get the current directory, it&#8217;s the &#8216;dirname&#8217; element of pathinfo(__FILE__). Generally, this will be the path under which you called php -a, but it can be slightly erratic. If you want to include other PHP files from the interactive shell (which can definitely be done, and is encouraged to test and play around with libraries), you may be safest using absolute paths.</p>
<p>Also, remember that you do not need to type in your PHP code to test it using the PHP binary. While this is outside the area of the interactive shell, calling &#8220;php filename.php&#8221; will execute filename.php as a standard PHP script, which may prove useful for cron jobs / scheduled tasks or just plain testing.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d168').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d168" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/&amp;title=Testing+PHP+with+the+interactive+shell" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/&amp;title=Testing+PHP+with+the+interactive+shell" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/&amp;title=Testing+PHP+with+the+interactive+shell" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/&amp;title=Testing+PHP+with+the+interactive+shell" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d168').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/testing-php-with-the-interactive-shell-168/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Building Web 2.0 Tag Clouds in PHP</title>
		<link>http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/</link>
		<comments>http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/#comments</comments>
		<pubDate>Fri, 02 May 2008 11:00:00 +0000</pubDate>
		<dc:creator>Akash Mehta</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/</guid>
		<description><![CDATA[Every major website seems to have a tag cloud. Users love tag clouds; they help navigate masses of content quickly and easily. When used appropriately, they help us sort filter through information stores, reduce the signal-to-noise ratio. Providing a tag cloud is also relatively painless for the server - after all, it&#8217;s just some HTML. [...]]]></description>
			<content:encoded><![CDATA[<p>Every major website seems to have a tag cloud. Users love tag clouds; they help navigate masses of content quickly and easily. When used appropriately, they help us sort filter through information stores, reduce the signal-to-noise ratio. Providing a tag cloud is also relatively painless for the server - after all, it&#8217;s just some HTML. But how do we actually build a tag cloud at application level? In this tutorial, I&#8217;ll take you through putting together a full-blown, calculated web 2.0 tag cloud in PHP. <span id="more-165"></span></p>
<p>First, let&#8217;s look at what we want to end up with. We&#8217;ll take this data:</p>
<blockquote><p>PHP: 30 items<br />
JavaScript: 24 items<br />
Java: 17 items<br />
Python: 26 items<br />
Ruby: 17 items</p>
</blockquote>
<p>And we want to end up with this tag cloud:</p>
<blockquote><p>
<a href="#" style="font-size: 40px">php</a> <a href="#" style="font-size: 30px">javascript</a> <a href="#" style="font-size: 18px">java</a> <a href="#" style="font-size: 33px">python</a> <a href="#" style="font-size: 18px">ruby</a>
</p>
</blockquote>
<p>To do this, we need to first examine what a tag cloud is like at HTML level. Each of these tags needs to be wrapped in an element that can have a style attribute. We&#8217;ll use that to set a font size. We could use either percentages or pixels; both have advantages and disadvantages. In this tutorial, we&#8217;ll do something like this:</p>

<div class="wp_syntax"><div class="code"><pre>&lt;a href=&quot;#&quot; style=&quot;font-size: 40px&quot;&gt;php&lt;/a&gt;
&lt;a href=&quot;#&quot; style=&quot;font-size: 30px&quot;&gt;javascript&lt;/a&gt;</pre></div></div>

<p>We&#8217;re using anchor tags so that we can later link them as needed.</p>
<p>So let&#8217;s start with our data. The above tag cloud was generated with this array:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$tags</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'php'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'javascript'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'java'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">17</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'python'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">26</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ruby'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">17</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>The next step in a tag cloud is calculating those font sizes. We need to define a minimum and maximum value for that font-size CSS parameter, so that we always know what sizes we&#8217;re dealing with. We then calculate the minimum and maximum values from the entire data set - array_values() will help us sort out the data - and the difference between these, the <em>spread</em> of the data.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$maxsize</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$minsize</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff0000">$maxval</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">array_values</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$minval</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">min</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">array_values</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff0000">$spread</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$maxval</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minval</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>Finally, we work out a &#8220;step&#8221;, or an increment value for each level of items. This step will be calculated based on the difference between minimum and maximum font size, divided by the spread. This gives us a relationship between number of items and pixels for font size.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">$step</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$maxsize</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minsize</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #ff0000">$spread</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>We can then work out the font size as the difference between the number of items for the current item and the lowest number of items (the minimum) in the set, multiplied by the step. This gives us the value of the font size of the current item in relation to 0. Finally, we add the minimum font size value for some width.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000066;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$minsize</span> <span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$value</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minval</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$step</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>Let&#8217;s take an example for a second. Take a new dataset, with javascript 5, php 6 and java 7. Our minimum font size is 20 and maximum size 30. Therefore $minval is 5, and $maxval is 7. Our $spread is 2, or 7-5. Our $step is ($maxsize - $minsize) / $spread, giving us 10 - 2 or 5. This means there is 4 pixels difference between each of our three values. PHP&#8217;s value would be calculated like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000066;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$minsize</span> <span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$value</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minval</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$step</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span>       <span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span>      <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>       <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>This gives us 25, or 25 pixels. It&#8217;s quite simple, really. Let&#8217;s put all this code together, including a simple loop to run over each of the tags and spit out the HTML within a function:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> tag_cloud<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #ff0000">$maxsize</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">40</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff0000">$minsize</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #ff0000">$maxval</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">array_values</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff0000">$minval</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">min</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">array_values</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #ff0000">$spread</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$maxval</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minval</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #ff0000">$step</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$maxsize</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minsize</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$spread</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #ff0000">$key</span> <span style="color: #66cc66;">=&gt;</span> <span style="color: #ff0000">$value</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #ff0000">$size</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$minsize</span> <span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$value</span> <span style="color: #66cc66;">-</span> <span style="color: #ff0000">$minval</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff0000">$step</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #000066;">echo</span> <span style="color: #ff0000;">'&lt;a href=&quot;#&quot; style=&quot;font-size: '</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$size</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">'px&quot;&gt;'</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$key</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">'&lt;/a&gt; '</span><span style="color: #66cc66;">;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #ff0000">$tags</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'php'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'javascript'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'java'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">17</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'python'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">26</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ruby'</span><span style="color: #66cc66;">=&gt;</span><span style="color: #cc66cc;">17</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
tag_cloud<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$tags</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>And we&#8217;re done! A simple yet powerful PHP script to generate a web 2.0 tag cloud for your website.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d165').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d165" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/&amp;title=Building+Web+2.0+Tag+Clouds+in+PHP" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/&amp;title=Building+Web+2.0+Tag+Clouds+in+PHP" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/&amp;title=Building+Web+2.0+Tag+Clouds+in+PHP" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/&amp;title=Building+Web+2.0+Tag+Clouds+in+PHP" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d165').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/building-web-2-0-tag-clouds-in-php-165/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Packaging a Wordpress Theme for Distribution</title>
		<link>http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/</link>
		<comments>http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 22:12:02 +0000</pubDate>
		<dc:creator>JonGos</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/</guid>
		<description><![CDATA[In my ten part series &#8220;Designing and Coding a Wordpress Theme From Scratch&#8221; we made our own Wordpress theme starting with a design in Photoshop. But now that you&#8217;ve made a theme, what about releasing it to the public?


So far I&#8217;ve released two themes: Tech Blogger and Unstandard Remix).  A third, my first completely [...]]]></description>
			<content:encoded><![CDATA[<p>In my ten part series <a href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-1-143/" target="_blank" title="photoshop to xhtml to wordpress theme">&#8220;Designing and Coding a Wordpress Theme From Scratch&#8221;</a> we made our own Wordpress theme starting with a design in Photoshop. But now that you&#8217;ve made a theme, what about releasing it to the public?</p>
<p><span id="more-162"></span></p>
<p><img src="http://farm3.static.flickr.com/2001/2449394258_676eb5ea2b.jpg"></p>
<p>So far I&#8217;ve released two themes: <a href="http://goscreative.blogspot.com/2008/04/free-wordpress-theme-unstandard-remix.html" target="_blank" title="tech blogger">Tech Blogger</a> and <a href="http://goscreative.blogspot.com/2008/04/free-wordpress-theme-unstandard-remix.html" target="_blank" title="unstandard remix">Unstandard Remix</a>).  A third, my first completely original theme, is still in development but I <a href="http://goscreative.blogspot.com/2008/05/free-wordpress-theme-aqua-marina.html" target="_blank">released it early</a> for the sake of my tutorial.</p>
<p>What do you need to do when you&#8217;re releasing your first theme be it modified or bespoke?  Here&#8217;s a checklist:</p>
<ul>
<li>Include a <strong>readme.txt</strong> file.  This file should contain installation instructions, release info and any notes you want the reader to be aware of before using your theme.  It really sucks when novices are downloading themes only to be 100% confused by what they&#8217;ve downloaded. It only means that they may delete your theme and download another one that they can more easily digest.  If your goal is maximum adoption, that&#8217;s not the route you want to go.</li>
<li>Test it. Think of every scenario you can possibly remember from your own blog use.  Try to be the use, do all the things that you think no one would ever do because (rest assured) that person is out there.  Are all your links functioning?  Are all your pages displaying correctly?  If not, is your 404.php page popping up when it should?  Make sure you&#8217;ve thought of EVERY possible scenario before you release your theme.  I can&#8217;t tell you how annoying it is download a theme that you like only to spend the next few hours debugging it to make it truly functional.</li>
<p><img src="http://farm4.static.flickr.com/3107/2455545152_636cce8a80.jpg"></p>
<li>Organize it.  You want your theme to be well organized so that it doesn&#8217;t take any longer than necessary to install and use it.  Put your actual theme in a parent folder labeled &#8216;theme&#8217; so the user can just drag and drop.  Place any plug-ins or widgets your theme uses in a parent folder called &#8216;plugins&#8217; so that the user can do the same.  If you&#8217;re including .psd label those in a folder that tells the user what it is. </li>
<li>Compress it. You&#8217;ll be hard-pressed to find a file host that makes it easy to share uncompressed folders.  This is because a folder is a directory and if you upload it virtually any service online it will be treated like a directory (if accepted at all).  Compress the file as either a .zip, .sit, .gzip or .tar.gz file.  This will make the files faster to download and it will allow the user to download with one click instead of several</li>
<li>Publish it.  Where will your theme live online?  Do you want it on your own web server or do you want it hosted on at repository like <a href="http://themes.wordpress.net/" target="_blank">themes.wordpress.net</a>?  I prefer to use repositories or file hosting services like <a href="http://mediafire.com/" target="_blank">mediafire.com</a></li>
<li>Announce it.  Unless a lot of people read your bog or visit your website, there&#8217;s no way for people to know what you&#8217;ve done.  If you&#8217;ve posted your theme to a repository like <a href="http://themes.wordpress.net/" target="_blank">themes.wordpress.net</a> then the job is already done.  However, you should tell your friends and submit it to some other sites so that the world is aware.</li>
</ul>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d162').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d162" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/&amp;title=Packaging+a+Wordpress+Theme+for+Distribution" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/&amp;title=Packaging+a+Wordpress+Theme+for+Distribution" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/&amp;title=Packaging+a+Wordpress+Theme+for+Distribution" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/&amp;title=Packaging+a+Wordpress+Theme+for+Distribution" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d162').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Designing and Coding a Wordpress Theme From Scratch (Part 10)</title>
		<link>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/</link>
		<comments>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 21:16:50 +0000</pubDate>
		<dc:creator>JonGos</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Photoshop]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/</guid>
		<description><![CDATA[Going From Photoshop to XHTML to Wordpress Theme.  In this multi-part series I'll detail how to create and design a Wordpress theme in Photoshop and take it from just an idea to fully coded.
]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-3-146/">Part 3</a> - &#8220;Photoshop to XHTML in 24 Hours&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-4-147/">Part 4</a> - &#8220;Cleaning Up Your XHTML&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/javascript/designing-and-coding-a-wordpress-theme-from-scratch-part-5-149/">Part 5</a> - &#8220;Preloading Images with Javascript and CSS&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/">Part 6</a> - &#8220;Marking Up is Hard to Do&#8221; and &#8220;The Anatomy of a Wordpress Theme&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/">Part 7</a> - &#8220;Beginning with PHP for Wordpress&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/">Part 8</a> - &#8220;Putting the Press in Wordpress with PHP&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/php/designing-and-…scratch-part-9designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/">Part 9</a> - &#8220;Marking Up Header.php, Footer.php and Sidebar.php&#8221;</p>
<p>So far we&#8217;ve made a ton of progress with our theme design.  We <a href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-2-144/" target="_blank" title="designing wordpress themes in photoshop">designed it</a> in Photoshop, we <a href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-4-147/" target="_blank" title="XHTML CSS to Wordpress theme">converted to XHTML</a> and then we began the somewhat tedious task of <a href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/" target="_blank" title="XHTML to PHP">adding PHP</a>.  Now that we&#8217;ve created index.php, header.php, footer.php and sidebar.php, we can move on to creating the rest of the theme.</p>
<p><span id="more-160"></span></p>
<p>In &#8220;The Anatomy of a Wordpress Theme&#8221; we noted that Wordpress needs <a href="http://www.wpdesigner.com/2007/03/27/wordpress-theme-checklist/" target="_blank">certain files</a> for your theme to function properly.  Here&#8217;s that list again:</p>
<ol>
<li>404 Template = 404.php</li>
<li><strike>Archive Template</strike> = <a href="http://codex.wordpress.org/Creating_an_Archive_Index" target="_blank">archive.php</a></li>
<li><strike>Archive Index Page</strike> = <a href="http://codex.wordpress.org/Creating_an_Archive_Index" title="_blank">archives.php</a></li>
<li>Comments Template = <a href="http://www.christianmontoya.com/2006/10/15/full-featured-commentsphp-template-for-wordpress/" target="_blank">comments.php</a></li>
<li><strong>Footer Template = footer.php</strong></li>
<li><strong>Header Template = header.php</strong></li>
<li>Links = links.php</li>
<li><strong>Main Template = index.php</strong></li>
<li>Page Template = page.php</li>
<li><strike>Popup Comments Template</strike> = <a href="http://codex.wordpress.org/Theme_Development" target="_blank">comments-popup.php</a></li>
<li>Post Template = single.php</li>
<li><strike>Search Form</strike> = <a href="http://codex.wordpress.org/search.php" target="_blank">searchform.php</a></li>
<li><strike>Search Template</strike> = <a href="" target="_blank">search.php</a></li>
<li><strong>Sidebar Template = sidebar.php</strong></li>
<li><strong>Stylesheet = style.css</strong></li>
</ol>
<p>As you may have noticed, the items listed in <strong>bold</strong> are the only items we&#8217;ve created in our lessons thus far and there is still a lot of work to be done!  Anything <strike>struck through</strike> is optional therefore this lesson won&#8217;t cover it but I have linked to pages where you can read about them on your own. While I can&#8217;t go into complete detail I will highlight some major points about each and then I&#8217;ll give you links to four sites that break the process down in detail and more thoroughly:</p>
<h2>single.php</h2>
<p>Single.php is the file referenced when someone clicks on the permalink for one of your posts.  Thus it is the template for displaying a single post on your blog.  On most blogs single.php an index.php are very similar except that in addition to querying <strong>&lt;? the content(); ?&gt;</strong> we also have to query the comments page. We do this just before we close the loop with:</p>
<pre>
	&lt;?php comments_template(); ?&gt;
</pre>
<h2>page.php</h2>
<p>Page.php is the template for any page in your theme that doesn&#8217;t have it&#8217;s own .php template or that is not a blog entry.  This is also the template for the static &#8220;Pages&#8221; that you create within the Wordpress Admin panel.  It is usually also just like index.php except that it doesn&#8217;t include <strong>the loop</strong> or <strong>the_content()</strong>.</p>
<h2>links.php</h2>
<p>Ignores Page content and instead displays your links using <strong>get_links_list</strong>.</p>
<h2>404.php</h2>
<p>Where you users land when they follow a bad link on your blog or click through to something that&#8217;s been removed.  <a href="http://codex.wordpress.org/Creating_an_Error_404_Page" target="blank">Codex</a> offers some advice&#8230;. </p>
<blockquote cite="http://codex.wordpress.org/Creating_an_Error_404_Page"><p>
While you work hard to make sure that every link actually goes to a specific web page on your site, there is always a chance that a link clicked will slam dunk and become a famous 404 ERROR PAGE NOT FOUND. Some errors are avoidable, you should regularly check and double check all your links. Also, if you are deleting a popular but out-of-date post, consider deleting the body of the post, and replacing it with a link referring visitors to the new page.
</p>
</blockquote>
<p>This concludes <a href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-3-146/">&#8220;Designing and Coding a Wordpress theme from Scratch&#8221;</a> .  This guide was written as a starting point and a reference guide I can always be contacted at <strong>jongos [at] gmail</strong> if you are having trouble or need advice.  Alternatively I&#8217;ve compiled a list of resources that I often reference when creating themes below.</p>
<p>In this tutorial I mentioned a theme that I was developing quite a bit.  You can download it along with the PSD used to create it <a href="http://www.developertutorials.com/blog/wp-content/uploads/2008/04/aqua-marina.zip" target="_blank">here</a>.  Keep in mind that the version you&#8217;re downloading is an early beta release.  It&#8217;s bulky, clunky, not very pretty under the covers and has a mind of it&#8217;s own so I&#8217;m dubbing it the Rosie O Donnell release.  Feel free to give me feedback on it, use it to double check your own code, or modify it to suit your needs.</p>
<p><strong>DOWNLOAD THE <a href="http://www.developertutorials.com/blog/wp-content/uploads/2008/04/aqua-marina.zip" target="_blank">AQUA MARINA</a> WORDPRESS THEME</strong></p>
<p><a href="http://goscreative.blogspot.com/2008/05/free-wordpress-theme-aqua-marina.html" target="_blank"><img src="http://farm3.static.flickr.com/2001/2449394258_676eb5ea2b_m.jpg"></a></p>
<hr />
<h2>Recommended Further Reading</h2>
<p><a target="_blank" title="understanding wordpress templates" rel="bookmark" href="http://codex.wordpress.org/">Stepping_Into_Templates</a><br />
<a target="_blank" title="html to xhtml" rel="bookmark" href="http://codex.wordpress.org/HTML_to_XHTML">HTML to XHTML</a><br />
<a target="_blank" title="create wordpress themes" rel="bookmark" href="http://www.wpdesigner.com/2007/02/19/so-you-want-to-create-wordpress-themes-huh/">So You Want To Create Wordpress Themes</a><br />
<a target="_blank" title="xhtml css to wordpress" rel="bookmark" href="http://theundersigned.net/2006/05/from-xhtmlcss-to-wordpress/">From XHTML/CSS to Wordpress</a><br />
<a href="http://www.tamba2.org.uk/wordpress/" target="_blank" title="tamba2 wordpress tutorials">Tamba2&#8217;s Guide</a><br />
<a href="http://www.wpdesigner.com/2007/08/10/how-to-slice-a-wordpress-theme/" target="_blank" title="Slicing a Wordpress Theme">Slizing a Wordpress Theme</a></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d160').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d160" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+10%29" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+10%29" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+10%29" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+10%29" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d160').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Designing and Coding a Wordpress Theme From Scratch (Part 9)</title>
		<link>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/</link>
		<comments>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 21:16:42 +0000</pubDate>
		<dc:creator>JonGos</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Photoshop]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[layout]]></category>

		<category><![CDATA[photshop]]></category>

		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/</guid>
		<description><![CDATA[Going From Photoshop to XHTML to Wordpress Theme.  In this multi-part series I'll detail how to create and design a Wordpress theme in Photoshop and take it from just an idea to fully coded.
]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-2-144/">Part 2</a> - &#8220;Layout And Structure&#8221; and &#8220;Designing Wordpress Themes in Photoshop&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-3-146/">Part 3</a> - &#8220;Photoshop to XHTML in 24 Hours&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-4-147/">Part 4</a> - &#8220;Cleaning Up Your XHTML&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/javascript/designing-and-coding-a-wordpress-theme-from-scratch-part-5-149/">Part 5</a> - &#8220;Preloading Images with Javascript and CSS&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/">Part 6</a> - &#8220;Marking Up is Hard to Do&#8221; and &#8220;The Anatomy of a Wordpress Theme&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/">Part 7</a> - &#8220;Beginning with PHP for Wordpress&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/">Part 8</a> - &#8220;Putting the Press in Wordpress with PHP&#8221;</p>
<p>Because Wordpress is fundamentally a PHP system we can add a few snippets of code to make our header, footer and sidebar files dynamic. </p>
<h2>Marking Up Header.php</h2>
<p>Your blog header file usually contains the title of your site linked to the homepage.  In an HTML page we would simply add text or place an image and link to the homepage using &lt;a href=&#8221;"&gt;&lt;/a&gt;.  The key to making our Wordpress theme, however, is we need to make all our links relative so that the end user can install the theme and use it with their own unique site with as little fuss as possible.  It should <i>just work</i>.</p>
<p><span id="more-159"></span></p>
<p>How is this done?  We use PHP requests to request and print the blog title allowing it to be dynamically relative to the database.</p>
<p>The code for a text blog title:</p>
<pre>
	&lt;div class="blogtitle"&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;/"&gt;
	&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/div&gt;
</pre>
<p>The code for an image blog title:</p>
<pre>
	&lt;div class="blogtitle"&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;/"&gt;
	&lt;img src="your/image/path.jpg" title="&lt;?php bloginfo('name'); ?&gt;" /&gt;
	&lt;/a&gt;&lt;/div&gt;
</pre>
<p>These are the only two codes we need to place in our header.php file.  In my case I needed to request other PHP documents that are meant to be displayed before the document continues: the sidebar and the center rotating headline areas. I this did using this code:</p>
<pre>
	&lt;?php require('yourphpfile.php'); ?&gt;
	&lt;?php get_sidebar(); ?&gt;
</pre>
<p>Still confused?  The image below contains a region map of my theme&#8217;s <strong>index.php</strong> as it displays in a browser.  The red region represents &#8220;header.php&#8221;, the purple region represents &#8220;center.php&#8221;, the blue region represents &#8220;sidebar.php&#8221; and the green is the post area, the code for which is contained in index.php.  </p>
<p><img src="http://farm3.static.flickr.com/2198/2454229161_0db7a57ec1.jpg"></p>
<p>Because the format of my blog is unique to my design this may not apply to your own design, I just want to make sure everything is throughly explained so that when you download my theme in <a href="http://www.developertutorials.com/blog/php/designing-and-…cratch-part-10designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/" target="_blank" title="photoshop to wordpress">Part 10</a> you&#8217;ll understand how everything works.</p>
<h2>Marking Up Footer.php</h2>
<p>Footer.php is even easier because there&#8217;s no crucial PHP requests that need to go here to make it function.  This means it can be entirely HTML or you can add a dynamic request for the blog title like you did above.  You may want to try something like this:</p>
<pre>
	&lt;div class="footer"&gt;©2008 &lt;a href="&lt;?php bloginfo('url'); ?&gt;/"&gt;
	&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/div&gt;
</pre>
<p>&#8230;which would simply display the copyright and year followed by the blog title.</p>
<h2>Marking Up Sidebar.php</h2>
<p>Sidebar.php is essentially the same in that it can contain nothing more than HTML or it can also contain PHP queries.  Here are some popular PHP queries often used in sidebar.php:</p>
<pre>
	&lt;strong&gt;Display the Blogroll:&lt;/strong&gt;
	&lt;?php get_links_list(); ?&gt;

	&lt;strong&gt;Display the pages of the site:&lt;/strong&gt;
	&lt;?php wp_list_pages('title_li=&lt;h2&gt;Pages&lt;/h2&gt;'); ?&gt;

	&lt;strong&gt;Display the site's categories:&lt;/strong&gt;
	&lt;?php wp_list_cats(); ?&gt;
</pre>
<p>I recommend reading <a href="http://codex.wordpress.org/Customizing_Your_Sidebar" target="_blank">&#8220;Customizing Your Sidebar&#8221;</a> if you&#8217;d like to explore your options a bit more.  In <a href="http://www.developertutorials.com/blog/php/designing-and-…cratch-part-10designing-and-coding-a-wordpress-theme-from-scratch-part-10-160/" target="_blank" title="photoshop to wordpress theme">Part 10</a> we&#8217;ll create the other pages of our theme and then we&#8217;ll learn all about<a href="http://www.developertutorials.com/blog/php/packaging-a-wordpress-theme-for-distribution-162/" target="_blank" title="Packaging a Wordpress Theme for Distribution">&#8220;Packaging a Wordpress Theme for Distribution&#8221;</a></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d159').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d159" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+9%29" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+9%29" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+9%29" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+9%29" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d159').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-9-159/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Learn regular expressions in PHP</title>
		<link>http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/</link>
		<comments>http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 11:00:04 +0000</pubDate>
		<dc:creator>Akash Mehta</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/</guid>
		<description><![CDATA[Love them or hate them, regular expressions are here to stay. When it comes to quickly dealing with large blocks of data, batch processing operations or screen scraping, regular expressions are often the most effective solution. There&#8217;s just one problem, though - learning them can be as hard as learning a new language altogether. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Love them or hate them, regular expressions are here to stay. When it comes to quickly dealing with large blocks of data, batch processing operations or screen scraping, regular expressions are often the most effective solution. There&#8217;s just one problem, though - learning them can be as hard as learning a new language altogether. Here&#8217;s how to get off to a flying start.</p>
<p><span id="more-152"></span></p>
<p>First, you need to how regular expressions work. Stick with PCRE - the preg_* functions - they&#8217;re faster, more reliable and expressions for them are more common. The different styles of regular expressions each define a mini language for matching patterns within a block of text. Screen scraping is probably the most popular example. Consider this:</p>

<div class="wp_syntax"><div class="code"><pre>&lt;a href=&quot;http://example.com/1&quot;&gt;1&lt;/a&gt;
&lt;a href=&quot;http://example.com/2&quot;&gt;Not 1.&lt;/a&gt;
&lt;a href=&quot;http://example.com/?query#someid&quot;&gt;Yet another link.&lt;/a&gt;</pre></div></div>

<p>What if you wanted to programmatically extract the link URLs and text from each of these? At this level of simplicty, some basic explode()s might be enough, and when you need to be more tolerant for the data, XML parsing is probably the way to go. But for now, just looking at that, regular expressions would be the easiest way. And we can build a pattern that defines what is to be matched so that the regular expression engine (in this case, PCRE) will find all matches and give them to us.</p>
<p>One of the best ways to understand regular expressions in practise, I find, is to consider mod_rewrite. You&#8217;ve seen those fantastic URLs on websites - e.g. http://example.com/users/myusername - these don&#8217;t actually exist as a file, but we can use Apache&#8217;s mod_rewrite engine to &#8220;rewrite&#8221; these URLs to other URLs. We might make that /users/(some username) go to /users.php?username=(the username). The best tutorial for this, by far, is <a href="http://corz.org/serv/tricks/htaccess2.php" target="_blank">the corz.org htaccess tips and tricks</a> guide. Have a very thorough read through this and experiment with it extensively before you go on.</p>
<p>Next, get equipped to test out regular expressions. You&#8217;re probably using Firefox. If you aren&#8217;t, <a href="http://getfirefox.com/" target="_blank">get it</a>. Then get the <a href="http://sebastianzartner.de/firefoxExtensions/RExT/" target="_blank">Regular Expressions Tester Firefox extension</a>. This will be invaluable for experimenting with regular expressions - the best way to learn.</p>
<p>Of course, you&#8217;ll need to be familiar with the PHP functions that will provide your regular expression workhorse. Bookmark <a href="http://www.developertutorials.com/php-manual/function.preg-match.html" target="_blank">the preg_match function&#8217;s manual entry</a> and refer back to it as you need to. The manual page has some invaluable examples which you should read through extensively.</p>
<p>Finally, when in doubt, keep a cheatsheet at hand. <a href="http://www.ilovejackdaniels.com/cheat-sheets/regular-expressions-cheat-sheet/">ILoveJackDaniels.com</a> has a fantastic <a href="http://www.ilovejackdaniels.com/regular_expressions_cheat_sheet.png" target="_blank">regular expression cheatsheet</a> that you should also bookmark.</p>
<p>With all these ready, you&#8217;ll be off to a great start. Remember, the best way to learn is to practise &#8212; read through real, working code, then write your own. Once you&#8217;ve finished all this, you&#8217;ll be a regular expression whiz in no time.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d152').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d152" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/&amp;title=Learn+regular+expressions+in+PHP" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/&amp;title=Learn+regular+expressions+in+PHP" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/&amp;title=Learn+regular+expressions+in+PHP" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/&amp;title=Learn+regular+expressions+in+PHP" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d152').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/learn-regular-expressions-in-php-152/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Designing and Coding a Wordpress Theme From Scratch (Part 8)</title>
		<link>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/</link>
		<comments>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 19:44:44 +0000</pubDate>
		<dc:creator>JonGos</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/</guid>
		<description><![CDATA[Going From Photoshop to XHTML to Wordpress Theme.  In this multi-part series I'll detail how to create and design a Wordpress theme in Photoshop and take it from just an idea to fully coded.
]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-1-143/">Part 1</a> - &#8220;Tools For The Task&#8221; and &#8220;Preparation&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-2-144/">Part 2</a> - &#8220;Layout And Structure&#8221; and &#8220;Designing Wordpress Themes in Photoshop&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-3-146/">Part 3</a> - &#8220;Photoshop to XHTML in 24 Hours&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-4-147/">Part 4</a> - &#8220;Cleaning Up Your XHTML&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/javascript/designing-and-coding-a-wordpress-theme-from-scratch-part-5-149/">Part 5</a> - &#8220;Preloading Images with Javascript and CSS&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/">Part 6</a> - &#8220;Marking Up is Hard to Do&#8221; and &#8220;The Anatomy of a Wordpress Theme&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/">Part 7</a> - &#8220;Beginning with PHP for Wordpress&#8221;</p>
<hr />
<h2>Putting the Press in WordPress with PHP</h2>
<p>Wordpress is <i>a state-of-the-art publishing platform with a focus on aesthetics, web standards, and usability</i> as the makers proudly proclaim at <a target="_blank" href="http://wordpress.org">wordpress.org</a>.  The keyword there being &#8216;publishing&#8217; and the most important part of the Wordpress publishing engine is the element that allows content to be published online easily and automatically.  This element is called the <strong>the loop</strong>.</p>
<p><span id="more-154"></span></p>
<p>While I can&#8217;t get into all the operational mechanics of how Wordpress works here, I can refer you to a page that does offer more in depth analysis (<a href="http://codex.wordpress.org" target="_blank">here</a>).  What is important to this tutorial is that the Wordpress theme we designed in Photoshop needs this PHP function (along with a few others) to correctly fetch content from the database.  Let&#8217;s examine four critical functions:</p>
<pre>
&lt;?php query_posts();?&gt;
<strong>Requests the database of content, should be placed near the top of index.php
just after the request &lt;?php get_header(); ?&gt;</strong>

&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;
<strong>this is The Loop and it should be placed prior to
where you want your content to print</strong>

&lt;?php the_content(&#8221;); ?&gt;
<strong>Calls and prints the content of your blog according to the settings in the
admin section or php functions called before it.  This should be placed wherever
you want your blog posts to go within the &lt;div&gt; tags.</strong>

&lt;?php endif; ?&gt;
<strong>Closes the loop.</strong>
</pre>
<p>Using the code from <a href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/">Part 7</a> as an example:</p>
<pre>
&lt;?php get_header(); ?&gt;
&lt;?php query_posts();?&gt;

    &lt;/div&gt;

	&lt;div id="post"&gt;
	  &lt;div class="entry"&gt;
	&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;

		&lt;div class="posts"&gt;
	&lt;?php the_excerpt(''); ?&gt;
     		&lt;/div&gt;   

	&lt;?php endif; ?&gt;
	  &lt;/div&gt;
     &lt;/div&gt;

&lt;?php get_footer(); ?&gt;
</pre>
<p>You may notice that the &lt;div&gt; tags with <strong>id</strong>  and <strong>class=&#8221;posts&#8221;</strong>elements.  These are styling anything they contain. My <strong>id=&#8221;post&#8221;</strong> is printing my photoshoped content area.  The area with <strong>id=&#8221;class&#8221;</strong> is formating how my content will be formated.  Do I want to justify text?  Do I want to use a text-transform on the first letter?  Change the color of text?  All those types of styles should be applied to this class to be passed on to the text inside the container.</p>
<p>These three lines alone are essentially all you need for index.php in your theme.  However, you&#8217;ll notice that we&#8217;re missing a few important items.  We need to call and style the posts name, permalink, and meta data individually.  This means we need to add the following:</p>
<pre>
&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
<strong>Requests the post tile and links to it. Place this before the post content.</strong>

&lt;?php the_time(&#8217;F j, Y&#8217;); ?&gt; at &lt;?php the_time(&#8217;g:i a&#8217;); ?&gt;
&lt;?php comments_popup_link(&#8217;| No Comments&#8217;, &#8216;| 1 Comment;&#8217;, &#8216;| % Comments;&#8217;); ?&gt;
<strong>Requests various types of information related to the post.  Place this just after the previous line.</strong>

&lt;?php the_category(&#8217;, &#8216;) ?&gt; &lt;?php the_tags(&#8217;| Tags: &#8216;, &#8216;, &#8216;, &#8221;); ?&gt;
&lt;?php edit_post_link(&#8217;| Edit&#8217;, &#8221;, &#8221;); ?&gt;&lt;/p&gt;
<strong>This calls the footer meta information for each individual post.
Place this after the content but before you close the loop.</strong>
</pre>
<p>After placing these codes my index.php looks something like this:</p>
<pre>
&lt;?php get_header(); ?&gt;
&lt;?php query_posts("showposts=2");?&gt;

	&lt;div id="post"&gt;
	&lt;div class="entry"&gt;
		&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;

   	&lt;span class="postname"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php
 the_title(); ?&gt;&lt;/a&gt;&lt;/span&gt;

    	&lt;p class="postinfo"&gt;

		&lt;?php the_time('F j, Y'); ?&gt; at &lt;?php the_time('g:i a'); ?&gt; &lt;?
php comments_popup_link('| No Comments', '| 1 Comment;', '| % Comments;'); ?&gt;&lt;/p&gt;

	&lt;div class="posts"&gt;
    		&lt;?php the_content(''); ?&gt;
         	&lt;p class="postinfo"&gt;Posted in &lt;?php the_category(', ') ?&gt; &lt;?php
 the_tags('| Tags: ', ', ', ''); ?&gt; &lt;?php edit_post_link('| Edit', '', ''); ?&gt;
&lt;/p&gt;

     	&lt;/div&gt;   

		&lt;?php endif; ?&gt;
	&lt;/div&gt;
	&lt;/div&gt;

    		&lt;?php get_footer(); ?&gt;
</pre>
<p>In Part 9 we&#8217;ll be discussing how to correctly markup header.php, footer.php and footer.php and in Part 10 we&#8217;ll create the other pages Wordpress needs.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d154').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d154" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+8%29" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+8%29" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+8%29" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+8%29" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d154').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-8-154/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Designing and Coding a Wordpress Theme From Scratch (Part 7)</title>
		<link>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/</link>
		<comments>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 13:51:45 +0000</pubDate>
		<dc:creator>JonGos</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[PHP Functions]]></category>

		<category><![CDATA[Photoshop]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/</guid>
		<description><![CDATA[Going From Photoshop to XHTML to Wordpress Theme.  In this multi-part series I'll detail how to create and design a Wordpress theme in Photoshop and take it from just an idea to fully coded.
]]></description>
			<content:encoded><![CDATA[<p>This is the seventh post in series about creating Wordpress themes with your Photoshop designs.  You may want to review before we continue&#8230;.</p>
<p><a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-1-143/">Part 1</a> - &#8220;Tools For The Task&#8221; and &#8220;Preparation&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-2-144/">Part 2</a> - &#8220;Layout And Structure&#8221; and &#8220;Designing Wordpress Themes in Photoshop&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-3-146/">Part 3</a> - &#8220;Photoshop to XHTML in 24 Hours&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-4-147/">Part 4</a> - &#8220;Cleaning Up Your XHTML&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/javascript/designing-and-coding-a-wordpress-theme-from-scratch-part-5-149/">Part 5</a> - &#8220;Preloading Images with Javascript and CSS&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/">Part 6</a> - &#8220;Marking Up is Hard to Do&#8221; and &#8220;The Anatomy of a Wordpress Theme&#8221;</p>
</p>
<hr style="margin-bottom:20px; height:1px; color:#cccccc;"/>
<h2>Beginning with PHP for WordPress</h2>
<ul>
<li>First we&#8217;ll duplicate <strong>index.html</strong> and rename the copy <strong>index.php</strong>.  We&#8217;re only keeping the original .html file for reference to make sure that the finished PHP operates and looks the same.</li>
<li>Let&#8217;s open index.php in our text editor.  Right now it&#8217;s just a .html renamed .php.  Our job is to make make it true PHP.</li>
<p><span id="more-153"></span></p>
<li>Go ahead and create some more blank documents in your theme folder.  Let&#8217;s call them header.php, footer.php and sidebar.php (if you have a side bar in your theme).  We&#8217;re going to divide the HTML into the major sections and make each section it&#8217;s own PHP file to be marked up separately.</li>
<li>Cut everything that you consider the header of your document.  Make sure all tags are closed.  Below you&#8217;ll find an example of my code which is really irrelevant, your own code will look and function differently based on your unique design. Still, for the sake of a working example:</li>
<pre>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;The Wonderful World of Web Design!&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;link rel="stylesheet" href="style.css" type="text/css" media="screen" /&gt;
&lt;script type="text/javascript" src="scripts/preload.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="container"&gt;
	&lt;div id="header"&gt;
    &lt;div class="description"&gt;The Blog Title&lt;/span&gt;&lt;/div&gt;
	&lt;/div&gt;
    &lt;div id="header-nav"&gt;&lt;div class="content"&gt;
    &lt;a href=""&gt;ADVERTISE&lt;/a&gt;  |
    &lt;a href=""&gt;CONTACT&lt;/a&gt;  |
    &lt;a href=""&gt;RSS&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
    &lt;div id="spacer1"&gt;&lt;/div&gt;
    &lt;div id="upper-menu"&gt;&lt;div class="navigation"&gt;
    &lt;a href=""&gt;HOME&lt;/a&gt;
    &lt;a href=""&gt;NEWS&lt;/a&gt;
    &lt;a href=""&gt;BLOG&lt;/a&gt;
    &lt;a href=""&gt;HIRE ME&lt;/a&gt;
    &lt;a href=""&gt;PORTFOLIO&lt;/a&gt;
    &lt;a href=""&gt;QUESTIONS&lt;/a&gt;
    &lt;a href=""&gt;LINKS&lt;/a&gt;
    &lt;a href=""&gt;POPULAR&lt;/a&gt;
    &lt;/div&gt;

    &lt;/div&gt;
	&lt;div id="right-top"&gt;&lt;/div&gt;

 &lt;!-- End header.php --&gt;
</pre>
<li>Paste your header information in to header.php.  Do the same for sidebar and your footer, cutting the code from index.php and pasting it in the corresponding file.</li>
<li>I use comment tags like <strong>&lt;!&#8211; End header.php &#8211;&gt;</strong> to write notes that help me remember what&#8217;s going on in my code.</li>
<li>If you do this correctly you&#8217;ll be left with a pretty sparse index.php document.  All that should be left is some That&#8217;s good because now we&#8217;re going to tell index.php where to find all the information we just moved.  We do this with PHP functions like so:</li>
<pre>
&lt;?php get_phpdocumentname(); ?&gt;
</pre>
<p>This <strong>get_</strong> function does exactly what it sounds like it goes and fetches a requested document and displays the contents of that document in the area requested.  My index.php document looked like this:</p>
<pre>
&lt;?php get_header(); ?&gt;

    &lt;/div&gt;

	&lt;div id="post"&gt;
	  &lt;div class="entry"&gt;

		&lt;div class="posts"&gt;
     		&lt;/div&gt;   

	  &lt;/div&gt;
	&lt;/div&gt;

&lt;?php get_footer(); ?&gt;
</pre>
<li>Ofcourse, for now we&#8217;ll leave the body &lt;div&gt;&#8217;s empty.  This is where our content will eventually go.
<p>You&#8217;ll notice that I have no sidebar, that&#8217;s because I call for it in the header.php document instead.  Why?  Because browsers read code from top to bottom and I want page to request the header and side bars to first before requesting the body.</p>
<p>In the next lesson we&#8217;ll start to analyze the PHP functions needed to request and display the dynamic content of a Wordpress theme.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d153').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d153" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+7%29" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+7%29" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+7%29" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+7%29" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d153').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Designing and Coding a Wordpress Theme From Scratch (Part 6)</title>
		<link>http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/</link>
		<comments>http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 12:37:31 +0000</pubDate>
		<dc:creator>JonGos</dc:creator>
		
		<category><![CDATA[Design]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[WordPress]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[theme]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/</guid>
		<description><![CDATA[Going From Photoshop to XHTML to Wordpress Theme.  In this multi-part series I'll detail how to create and design a Wordpress theme in Photoshop and take it from just an idea to fully coded.
]]></description>
			<content:encoded><![CDATA[<p>This is the sixth post in series about creating Wordpress themes with your Photoshop designs.  You may want to review before we continue&#8230;.</p>
<p><a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-1-143/">Part 1</a> - &#8220;Tools For The Task&#8221; and &#8220;Preparation&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-2-144/">Part 2</a> - &#8220;Layout And Structure&#8221; and &#8220;Designing Wordpress Themes in Photoshop&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-3-146/">Part 3</a> - &#8220;Photoshop to XHTML in 24 Hours&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-4-147/">Part 4</a> - &#8220;Cleaning Up Your XHTML&#8221;<br />
<a target="_blank" href="http://www.developertutorials.com/blog/javascript/designing-and-coding-a-wordpress-theme-from-scratch-part-5-149/">Part 5</a> - &#8220;Preloading Images with Javascript and CSS&#8221;</p>
<hr style="margin-bottom:20px; height:1px; color:#cccccc;"/>
<h2>Marking Up Is Hard To Do</h2>
<p>Wikipedia defines the term markup as <i>a set of annotations to text that describe how it is to be structured, laid out, or formatted.</i>  When we say we&#8217;re going to &#8216;mark something up&#8217; it means we&#8217;re formatting the document so that it can be read correctly by machines.  Hypertext Markup Language (HTML) is the most common form.  That can be marked up to Extensible Hyper-text Markup Language (XHTML) and beyond that to PHP to become dynamic.</p>
<p>Now that we&#8217;ve got our basic html layout design we can begin the hard work the transition from HTML to PHP.</p>
<p><span id="more-151"></span></p>
<h2>Anatomy of a WordPress Theme</h2>
<p>Before we get ahead of ourselves let&#8217;s analyze exactly what Wordpress is expecting from a theme.  The Wordpress engine works primarily using separate PHP files for the different components of the core engine. The various parts of your theme will simply call for various parts of the core engine to display content.  This makes it easy for you to style sections individually.  It also can allow for some incredibly complex themes that are built on the Wordpress engine.  Themes like the <a target="_blank" href="http://5thirtyone.com/archives/886">The Unstandard</a> by Derek Punsalan and <a target="_blank" href="http://www.deanjrobinson.com/redoable/redoable-10-theme-for-wordpress/">Redoable</a> are great examples of how to rethink the Wordpress theme impressively.</p>
<blockquote cite="http://codex.wordpress.org/Using_Themes"><p>Fundamentally, the WordPress Theme system is a way to &#8220;skin&#8221; your weblog. Yet, it is more than just a &#8220;skin.&#8221; Skinning your site implies that only the design is changed. WordPress Themes can provide much more control over the look and presentation of the material on your website.</p>
<p>A WordPress Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. A theme modifies the way the site is displayed, without modifying the underlying software. Themes may include customized template files, image files (*.jpg, *.gif), style sheets (*.css), custom Pages, as well as any necessary code files (*.php).</p>
</blockquote>
<p>Here are the things Wordpress looks for a theme file:</p>
<ol>
<li>404 Template = 404.php</li>
<li>Archive Template = archive.php</li>
<li>Archive Index Page = archives.php</li>
<li>Comments Template = comments.php</li>
<li>Footer Template = footer.php</li>
<li>Header Template = header.php</li>
<li>Links = links.php</li>
<li>Main Template = index.php</li>
<li>Page Template = page.php</li>
<li>Popup Comments Template = comments-popup.php</li>
<li>Post Template = single.php</li>
<li>Search Form = searchform.php</li>
<li>Search Template = search.php</li>
<li>Sidebar Template = sidebar.php</li>
<li>Stylesheet = style.css</li>
</ol>
<p>For the most part, if you&#8217;re missing any of these parts your theme either won&#8217;t work or won&#8217;t fully function the way Wordpress wants it to.  So far the only thing we&#8217;ve completed is <strong>stylesheet.css</strong> so where do the rest come from?  In <a href="http://www.developertutorials.com/blog/php/designing-and-coding-a-wordpress-theme-from-scratch-part-7-153/">Part 7</a> we&#8217;ll create <strong>index.php</strong> and start marking up our XHTML to PHP.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d151').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d151" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+6%29" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+6%29" title="Add to&nbsp;digg"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+6%29" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/&amp;title=Designing+and+Coding+a+Wordpress+Theme+From+Scratch+%28Part+6%29" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.developertutorials.com/blog/wp-content/plugins/social_bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d151').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.developertutorials.com/blog/design/designing-and-coding-a-wordpress-theme-from-scratch-part-6-151/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
