<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sirius Graphix &#187; Coding</title>
	<atom:link href="http://siriusgraphix.com/category/coding/feed" rel="self" type="application/rss+xml" />
	<link>http://siriusgraphix.com</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2010 17:36:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HTML/PHP: Sidebars, and What Have YOU Done Lately?</title>
		<link>http://siriusgraphix.com/html-php-sidebars-and-what-have-you-done-lately</link>
		<comments>http://siriusgraphix.com/html-php-sidebars-and-what-have-you-done-lately#comments</comments>
		<pubDate>Thu, 15 Jul 2010 10:05:26 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1652</guid>
		<description><![CDATA[The sidebar is all sorts of useful. There&#8217;s no limit on the number of different sorts of things that could go in a sidebar. Your RSS button? Definitely. Ads? For sure! A video? Heck, why not? You can even have multiple sidebars&#8230; one on each side of your content, or two right next to each [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright"><img class="alignright" title="What's in YOUR sidebar?" src="http://farm5.static.flickr.com/4137/4795447703_32e8c66da9_o.png" alt="What's in YOUR sidebar?" width="300" /></div>
<p>The sidebar is all sorts of useful.  There&#8217;s no limit on the number of different sorts of things that could go in a sidebar.  Your RSS button?  Definitely.  Ads?  For sure!  A video?  Heck, why not?</p>
<p>You can even have multiple sidebars&#8230; <a href="http://sushiday.com">one on each side of your content</a>, or <a href="http://fridgg.com/blog">two right next to each other</a>, on the same side of your content.  Cool, isn&#8217;t it?</p>
<p>Some things are pretty easy.  Your RSS button is likely an image, a link, and maybe some text or an email sign-up form.  Ads aren&#8217;t much different.  For videos, you just have to insert the code <a href="http://youtube.com">YouTube</a> (or whatever video site you&#8217;re using) gives you for embedding.  With <a href="http://siriusgraphix.com/author/sushi">basic knowledge about HTML</a>, you can certainly figure out how to do these things.</p>
<p>But what if you want to do something more involved&#8230; like list your most recent posts in your sidebar, or put WordPress widgets in your sidebar, or have multiple sidebars, or even have different sidebars on different pages of your website?  That involves a little more than just knowing how to use HTML tags and nest them properly.  For that, we have to get into PHP a bit.</p>
<p><strong>What have you been up to lately?</strong></p>
<p>Something that&#8217;s super useful to your readers (and can help your recent posts get more traffic, which is always good!) is to have a short list of your most recent posts in your sidebar.  Usually this list includes links to the five most recent posts.  In theory, this is pretty easy to do.  You just have to call the get_posts(); <a href="http://siriusgraphix.com/php-getting-functional">PHP function</a> (you remember <a href="http://siriusgraphix.com/php-were-going-elephpant-hunting">what PHP is</a>, right?), pass in the appropriate <a href="http://siriusgraphix.com/php-getting-functional#parameters">parameters</a>, and voila, there you go!</p>
<p>But this ain&#8217;t no computer science class, and I&#8217;m not some snobby professor who expects you to instantaneously understand every piece of code I throw at you.  Here, we&#8217;re all about understanding things&#8230; really, truly understanding them.  So we&#8217;re going to go through this line by line.</p>
<p>First, the code:<code>&lt;h2>Recent Posts&lt;/h2><br />
&lt;ul><br />
	<span class="tab">&lt;?php $recent = get_posts('posts_per_page=5')?><br />
	&lt;?php foreach ($recent as $post) : ?><br />
		<span class="tab">&lt;li>&lt;a href="&lt;?php echo(get_permalink($post->ID)) ?>">&lt;?php echo($post->post_title) ?>&lt;/a>&lt;/li></span><br />
	&lt;?php endforeach; ?></span><br />
&lt;/ul></code> That first line&#8217;s easy enough to understand, right?  It&#8217;s just your title &#8211; &#8220;Recent Posts&#8221; that you put in a header tag.  Really, you can name it whatever you&#8217;d like, but we&#8217;re going to name it &#8220;Recent Posts&#8221; for now.</p>
<p>Next, the opening &lt;ul> tag.  The function we use to display the list of posts outputs an array.  We want to take this array, and turn it into a list&#8230; an <em>unordered</em> list, so we use the &lt;ul> tag.</p>
<p>The next line isn&#8217;t HTML at all.  But you recognize that style of code, <a href="http://siriusgraphix.com/php-were-going-elephpant-hunting">right?</a>  The tags at the beginning and the end of the line tell you that it&#8217;s PHP.  Then we assign whatever we get from the <a href="http://codex.wordpress.org/Function_Reference/get_posts">get_posts()</a> <a href="http://siriusgraphix.com/php-getting-functional">function</a> to a <a href="http://siriusgraphix.com/php-variables">variable</a> called $recent &#8211; you&#8217;ll see why in a moment, but first I want to explain this function to you.</p>
<p>The <a href="http://codex.wordpress.org/Function_Reference/get_posts">get_posts()</a> <a href="http://siriusgraphix.com/php-getting-functional">function</a> does exactly what it says it does.  It gets your posts!  But how many?  And what if you want only the ones from a certain category, or ordered a specific way, or from a specific date&#8230;?  Thats what parameters are for.  Here, we&#8217;re just using one parameter &#8211; posts_per_page &#8211; to tell the function that we only want to display five posts.  But there are lots more possible parameters you can use&#8230; check out <a href="http://codex.wordpress.org/Function_Reference/get_posts">these</a> <a href="http://codex.wordpress.org/Template_Tags/query_posts#Parameters">two</a> pages to see a list of all the possible parameters that can be used with this function.</p>
<p>Now that we&#8217;ve got the information we need and have assigned it to a variable, we need to display it.  In order to do this, we need to use a <a href="http://siriusgraphix.com/php-getting-loopy">loop</a>.  Since the information is outputted in an array, we need to use a <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things#foreach">foreach loop</a>.  It&#8217;s not as hard as it looks.  We&#8217;re pretty much saying we want to look at each thing in the $recent array, and we&#8217;re going to call it a $post.  Then we do the stuff inside of the foreach loop&#8230; and continue to do it to each thing in the $recent array, until there aren&#8217;t any left.</p>
<p>So what is it that we&#8217;re doing inside of the foreach loop?  Well, we&#8217;re displaying the recent posts, that&#8217;s all.  Since we decided that this should be an unordered list (hence the &lt;ul> tags) then each item in the list needs to be in &lt;li> tags.  Easy.  Then we need to display the actual recent posts &#8211; each of which needs to consist of a link (because what&#8217;s the point of a list of your recent posts, if you can&#8217;t easily get to them?) and the title of the post.  We start out as we would for any ordinary link &#8211; with an &lt;a href=&#8221;">.  Then we need the link itself inside those quotes.</p>
<p>The cool thing with these items in the $recent array is that each item has certain other values associated with them.  So you can say $post->ID and it will give you the ID of the post, or $post->post_title to get the title.  Awesome, right?  So we use $post->ID in conjunction with the <a href="http://codex.wordpress.org/Function_Reference/get_permalink">get_permalink()</a> function (which takes in an ID of a post and returns the link for that post) to get the link.  Remember to surround that with &lt;?php and ?> tags to indicate that this is PHP code, and use the echo() function to display the output (otherwise it just sits there, and your browser doesn&#8217;t know what to do with it.)</p>
<p>After that, you need some text for the link, so it&#8217;s super easy to echo $post->post_title, which &#8211; you guessed it! &#8211; gives you the title of the post.  Then just close your tags, end the loop&#8230; and voila!  You have a list of your most recent posts!</p>
<p><strong>More sidebar magic</strong></p>
<p>Recent posts are awesome, and definitely good to have in your sidebar.  But there&#8217;s more to the sidebar than just its content&#8230; what if you want to use the built in WordPress sidebar widgets, or have different sidebars on different pages of your website?  You can be sure there&#8217;s much more fun to be had with the sidebars&#8230; next week!</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/html-php-sidebars-and-what-have-you-done-lately/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>HTML: Footer</title>
		<link>http://siriusgraphix.com/html-footer</link>
		<comments>http://siriusgraphix.com/html-footer#comments</comments>
		<pubDate>Thu, 06 May 2010 12:00:30 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1455</guid>
		<description><![CDATA[Photo courtesy of Allison Day For the last few weeks, we&#8217;ve been talking about the header of your website. So what&#8217;s next? Well, there&#8217;s the content section of you website, which changes on every page, and the sidebar, which can get complicated as well. So I thought this week, we&#8217;d take a little break and [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright"><img class="alignright" title="Footprint" src="http://farm3.static.flickr.com/2801/4464350212_8fa05b23e1_b.jpg" alt="Footprint" width="300" /><br /><small>Photo courtesy of <a href="http://www.flickr.com/photos/ballerinagirl/">Allison Day</a></small></div>
<p>For the last few weeks, we&#8217;ve been talking about the <a href="http://siriusgraphix.com/author/sushi">header</a> of your website.  So what&#8217;s next?  Well, there&#8217;s the content section of you website, which changes on every page, and the sidebar, which can get complicated as well.  So I thought this week, we&#8217;d take a little break and talk about the footer &#8211; the easiest section of your website.</p>
<p><strong>Elements of Your Footer</strong></p>
<p>The footer is the very, very, very last section of your website.  It goes at the bottom, or foot of every page&#8230; hence the name.  And it&#8217;s pretty much the same on every page, so just as we did for the header, we can use just one footer.php file and include it on every page in your website.  Within that file, you&#8217;re probably going to want to put all the footer elements in a &lt;div>, like this:<code>&lt;div id="footer"><br />
	<span class="tab">(footer stuff)</span><br />
&lt;/div></code></p>
<p>So what goes in the footer?  Well, some people put a smaller version of their <a href="http://siriusgraphix.com/html-navigation">navigation</a> in the footer, <a href="http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row">displayed horizontally</a> just like in the nav bar.  This is super easy to do &#8211; you can do it <a href="http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row">exactly the same way as we did it in the header</a> (but use a different id&#8230; remember, you should <a href="http://siriusgraphix.com/html-a-classy-identity">never use the same id twice on a page</a>!).</p>
<p>Another thing that a lot of people put in the header is their blog&#8217;s copyright.  Another easy thing to do.  Just put something like this in your footer:<code>&lt;p>Copyright &amp;copy; &lt;?php echo date('Y'); ?> · blue sun studio, inc.· All rights reserved</code> (Look!  That&#8217;s what we have at the bottom of <a href="http://siriusgraphix.com/">our website</a>!)  &amp;copy; displays the &copy; symbol, and if you remember <a href="http://siriusgraphix.com/php-on-one-condition">our lessons on PHP</a>, then this should look familiar to you &lt;?php echo date(&#8216;Y&#8217;); ?>  Easy, yes?</p>
<p><strong>Remember to Close The Door On Your Way Out&#8230;</strong></p>
<p>Those are pretty much all the important elements of a footer.  But there&#8217;s one more thing that&#8217;s very important&#8230;</p>
<p>I can almost guarantee that you will open tags in the header.php file&#8230; but you won&#8217;t close them.  Take, for example, the &lt;body> tag.  You don&#8217;t see a &lt;/body> tag anywhere, do you?  Nope.  So you need to remember to close that, and any other tags you may have opened but not closed in the header, in your footer.php file.  The closing body tag should be the very, very last thing in your footer file.  Any other tags that need to be closed will depend on what you want to include in them (sometimes you want to have one big #content div that includes the footer, so you&#8217;d close it after the closing div tag for the footer.  Other times you don&#8217;t want the footer to be a part of it, so you&#8217;ll close the #content div before you open the #footer div.)</p>
<p>Many of you will also have analytics code, for tracking the number of unique visits, pageviews, etc. that your site gets.  That usually goes at the very end&#8230; just <em>before</em> the closing &lt;/body> tag.</p>
<p><strong>Meet Me At The (Side)Bar&#8230;</strong></p>
<p>And that&#8217;s all there is to the footer.  No, seriously.  It&#8217;s that easy.</p>
<p>But I&#8217;ll bet by now, you&#8217;re ready for a nice, cool drink&#8230; of fresh water, of course.  (Or a <a href="http://siriusgraphix.com/who-spilled-the-beans">Las Vegas Cowtail</a>, perhaps?)</p>
<p>So next week, we&#8217;re going bar hopping!  Wait.  That doesn&#8217;t sound right&#8230; hold on&#8230;</p>
<p>We&#8217;re going <em>side</em>bar hopping!  Even more exciting!</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/html-footer/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML: Header Accessibility</title>
		<link>http://siriusgraphix.com/html-header-accessibility</link>
		<comments>http://siriusgraphix.com/html-header-accessibility#comments</comments>
		<pubDate>Thu, 29 Apr 2010 12:00:45 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1430</guid>
		<description><![CDATA[Photo courtesy of Phu Son Nguyen By now, your header&#8217;s rockin&#8217;, I just know it. You know how to put a cool background on it, use one of WordPress&#8217; built-in functions to put all your pages in the navigation, make your list of pages display nicely as a horizontal navigation, and use CSS to add [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright"><img class="alignright" title="Snow monkeys in Nagano, Japan - 'see no... website?'" src="http://farm4.static.flickr.com/3172/4562239031_fea43909ba.jpg" alt="Snow monkeys in Nagano, Japan - 'see no... website?'" width="300" /><br /><small>Photo courtesy of <a href="http://www.flickr.com/photos/phuson/">Phu Son Nguyen</a></small></div>
<p>By now, your header&#8217;s rockin&#8217;, I just know it.  You know how to <a href="http://siriusgraphix.com/html-an-intro-to-headers">put a cool background on it</a>, <a href="http://siriusgraphix.com/html-navigation">use one of WordPress&#8217; built-in functions to put all your pages in the navigation</a>, <a href="http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row">make your list of pages display nicely as a horizontal navigation</a>, and <a href="http://siriusgraphix.com/htmlcss-hovering-in-your-navigation">use CSS to add cool, classy effects to your navigation when anyone hovers or selects one of the pages</a>.</p>
<p>But there are still a few more important things to talk about in your header.  Though these last few tips don&#8217;t have much to do with how your header <em>looks</em>, they&#8217;re just as important as putting a background on you header or making your navigation bar look nice.</p>
<p><strong>Time To Go Home</strong></p>
<p>Pop quiz: which page on your website are people going to go to most?  The answer&#8217;s easy, and although every website is different, the answer is the same for 99% of you: your homepage is the page that people will visit the most.  So, as the owner of the website, you want to make it super-easy for people to get there.  Some people put a link in the navigation.  While this helps, there&#8217;s an even better solution: your header itself.  In fact, it&#8217;s <em>expected</em> that clicking on the logo of your website, or your header, will get people back to the homepage.  Otherwise people will spend a lot of time clicking there, and get frustrated when they find out it isn&#8217;t even a link&#8230; or it goes somewhere unexpected.</p>
<p>Ideally, we want the entire header to be a link&#8230; except for the navigation, of course.  It would be pretty silly to have your entire navigation link to the homepage, when you really want it to link to each of the individual pages on your website.  Usually, the area that you want to be clickable is going to be a big rectangle (technically it&#8217;s possible to make almost <em>any</em> shape of area clickable, using a combination of <a href="http://www.w3schools.com/tags/tag_map.asp">&lt;map></a> and <a href="http://www.w3schools.com/tags/tag_area.asp">&lt;area></a> tags&#8230; but it&#8217;s very rare to see that used, and involves a lot more work than your typical rectangle, so we&#8217;re not going to go into that today).</p>
<p>Our rectangle needs to have a width and a height (otherwise, how will your browser know what area is supposed to be clickable?).  This is easy to do, using the <a href="http://www.w3schools.com/css/pr_dim_height.asp">height</a> and <a href="http://www.w3schools.com/css/pr_dim_width.asp">width</a> properties in CSS, like this:<code>#header h1 a {<br />
	<span class="tab">height: 200px;<br />
	width: 900px;</span><br />
}</code>  However&#8230; if you do that and nothing else, your area still isn&#8217;t going to be a big old link like we want it to be.  Why?  Well, we can think of it as a big <em>block</em> of area.  But right now, we&#8217;re not telling our browser that&#8230; so we need to add one more property to our CSS &#8211; display:block;. <code>#header h1 a {<br />
	<span class="tab">height: 200px;<br />
	width: 900px;<br />
	display: block;</span><br />
}</code> This (obviously) tells our link to display as a block!  Woo!  How easy is that?</p>
<p><strong>See No Website&#8230; Hear No Website?</strong></p>
<p>Another thing that might not immediately come to mind when you&#8217;re developing your website, but that is also very important, is accessibility.  Ideally, you want <em>everyone</em> to be able to use your website, even if they&#8217;re blind, or deaf, or otherwise impaired such that they cannot enjoy your website to its fullest extent.  In addition, some people choose to keep JavaScript or CSS disabled &#8211; while they won&#8217;t be able to view your website as it was meant to be enjoyed, you still want them to be able to use your website.</p>
<p>One thing that we do, that you might have seen before, is put &#8216;alt&#8217; attributes on images, so there&#8217;s text associated with each image for screen readers to read.  But when we <a href="http://siriusgraphix.com/html-an-intro-to-headers">created our header</a>, we didn&#8217;t use an &lt;img src=&#8221;" alt=&#8221;" /> tag to create our image&#8230; instead we put it as a background on one of our header &lt;div>s.  This means we can&#8217;t use the &#8216;alt&#8217; attribute.  So what do we do?</p>
<div class="alignleft"><img class="alignleft" title="Snow monkeys in Nagano, Japan - 'speak no... website?'" src="http://farm4.static.flickr.com/3124/4563395851_698bff39be.jpg" alt="Snow monkeys in Nagano, Japan - 'speak no... website?'" width="300" /><br /><small>Photo courtesy of <a href="http://www.flickr.com/photos/phuson/">Phu Son Nguyen</a></small></div>
<p>For most of us, we&#8217;re not using actual text in our header image&#8230; the blog title (and any other relevant text) is probably part of the image itself.  So what we can do is add an &lt;h1> element (that means header 1 &#8211; since the biggest and most important header on your website is the header that we&#8217;ve been discussing these last few weeks, and everything else is sub-headers) and put our blog title there.  But&#8230; ew.  You do that, and the text shows up right on top of your pretty header image.  Doesn&#8217;t look so great, does it?  Okay, so something needs to change.</p>
<p>Luckily, we have the <em>text-indent</em> property in CSS.  We can put this property on the header&#8217;s &lt;h1>, and set it to -9999px&#8230; that&#8217;s so far negative, there&#8217;s not a chance in heck it&#8217;ll show up on your actual website.  It might seem like there&#8217;s no point in putting up a title that&#8217;s not going to show up&#8230; but anyone with CSS disabled will be able to see it, and things like screen readers and the spiders and bots from places like Google, Yahoo, or Bing will be able to see and understand this, even though the image means little to them.  A good thing for your website&#8217;s search ranking, and a very, very good thing for accessibility.</p>
<p><strong>That&#8217;s All, Folks!</strong></p>
<p>Can you believe it?  That wraps up everything I wanted to tell you about the header!  Of course, if you have any additional questions, you can always ask in the comments section or even <a href="http://siriusgraphix.com/contact">send me an email</a>.  Next week, we go to the very end of your website&#8230; the footer.  But don&#8217;t worry, that doesn&#8217;t mean we&#8217;ll never talk about everything in between&#8230; all in due time, my friends.  All in due time.</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/html-header-accessibility/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HTML/CSS: Hovering In Your Navigation</title>
		<link>http://siriusgraphix.com/htmlcss-hovering-in-your-navigation</link>
		<comments>http://siriusgraphix.com/htmlcss-hovering-in-your-navigation#comments</comments>
		<pubDate>Thu, 22 Apr 2010 12:00:37 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1401</guid>
		<description><![CDATA[Now that you&#8217;ve got your navigation lining up all prettily, what&#8217;s next? Well, you could stop there, if you wanted. But there&#8217;s so much more you could do using the wonders of CSS, to make your navigation (and soon your entire blog!) even more beautiful. Prettify Your World! Or At Least Your Navigation&#8230; There are [...]]]></description>
			<content:encoded><![CDATA[<p>Now that you&#8217;ve got your <a href="http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row">navigation lining up all prettily</a>, what&#8217;s next?  Well, you could stop there, if you wanted.  But there&#8217;s so much more you could do using the wonders of CSS, to make your navigation (and soon your entire blog!) even more beautiful.</p>
<p><strong>Prettify Your World! Or At Least Your Navigation&#8230;</strong></p>
<p>There are all sorts of different properties that you can use to style your navigation &#8211; both on the &lt;ul> (if you want to style the navigation as a whole), or on the &lt;li> if you want styles on each of the individual items in the navigation.  (Remember <a href="http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row">last week</a>, how we used the cookie crumbs to see where we were within the HTML, to style it in CSS.)  For example, if you want all of the text in your navigation to be black, then you could do <code>#navigation ul {<br />
	<span class="tab">color: #000000;</span><br />
}</code> But if you wanted space between each of the items in your navigation, you would put a padding attribute on the &lt;li>s, since it affects each individual list item, rather than the entire block of navigation, like this: <code>#navigation ul li {<br />
	<span class="tab">padding: 5px 10px 5px 0px;</span><br />
}</code> There are <a href="http://www.w3schools.com/css/css_reference.asp">all sorts of different CSS attributes</a> that you can use in your navigation&#8230; as always, if you have any questions about any of them, just ask!</p>
<p>Another cool thing that you see on a lot of navigations is how something will change when you hover over a page, or when that page is selected.  We don&#8217;t do that here on Sirius, but if you go visit <a href="http://lifeslittleinspirations.com/">Life&#8217;s Little Inspirations</a> or <a href="http://sayanouchi.com/">Saya No Uchi</a> and hover your mouse over any of the pages in their navigation bars, you&#8217;ll see what I mean.  In addition, we have the cool feature here on Sirius that when you&#8217;re on a page (click on our <a href="http://siriusgraphix.com/about">About page</a>, you&#8217;ll see what I mean), that page is highlighted in some way in the navigation bar.</p>
<p><strong>Anyone Else Have That Hoverround Song In Their Heads?</strong></p>
<p>It&#8217;s cool and all, but how do you do it?  It&#8217;s easier than it looks.  First of all, realize that all of your navigation items must be links.  After all, isn&#8217;t that the entire purpose of your navigation?  You want to enable your users to get to the different parts of your website&#8230; so of course, each item in the navigation must be a link.  So it ends up looking something like this:<code>&lt;div id="navigation"><br />
	<span class="tab">&lt;ul><br />
		<span class="tab">&lt;li><br />
			<span class="tab">&lt;a href="http://yourpage.com">Page&lt;/a></span><br />
		&lt;/li></span><br />
	&lt;/ul></span><br />
&lt;/div></code> Of course, with more &lt;li>s in there, and each with an &lt;a href=&#8221;"> inside of it, but you get the drift.</p>
<p>So you have all those links.  Because this is the way that HTML was made, the &lt;a>s are what you hover your mouse over.  (You know how when you hover your mouse over any normal link, and half the time it changes color?  This is the same principle.)  So you want to put the hover property on the link.  How do you do this?  Like this:<code>#navigation ul li a:hover {<br />
	<span class="tab">(whatever styles you want to change when you hover over the item in the navigation)</span><br />
}</code> You can put whatever styles you want there&#8230; make it change color, add a border to it, change the background&#8230; the possibilities are endless.</code></p>
<p><strong>I Choose You, Pikachu!</strong></p>
<p>The really, super cool thing about this is... if you want to add styles for the "selected" page (like when we went and looked at Sirius' <a href="http://siriusgraphix.com/about">About page</a>, and saw that "About" was highlighted in the navigation bar)... it's almost exactly the same as the hovering that we just did.  Seriously.  Only one little change.  Awesome, isn't it?</p>
<p>Instead of putting your styles on <code>#navigation ul li a:hover {}</code> you instead put them on <code>#navigation ul li.current_page_item a {}</code> And then you put whatever styles you want on it, just as you did with the hover.</p>
<p><strong>So, What Have We Learned Today?</strong></p>
<p>(I mean, aside from the fact that Allison consistently stays up working into the wee hours of the morning, and grew up in the age of Pokemon.)</p>
<p>We've learned that CSS makes our lives a heck of a lot easier, and lets us do all sorts of fun things to make our website just as gorgeous as we are!  Yes, it's wonderful.  And, as always, there's much more to come...</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/htmlcss-hovering-in-your-navigation/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML/CSS: Navigation: All Your Cookies In A Row</title>
		<link>http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row</link>
		<comments>http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row#comments</comments>
		<pubDate>Thu, 15 Apr 2010 16:12:43 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1381</guid>
		<description><![CDATA[Photo courtesy of Phu Son Nguyen Last week, we discussed the super-cool wp_list_pages($args) function, and how it can make creating your navigation on your website super easy. If you want your navigation in your sidebar, for example, or anywhere else as a vertical list, then this already works perfectly. But what if you want it [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright"><img class="alignright" title="The cookies are in line, your navigation should be too!" src="http://farm4.static.flickr.com/3661/3421037994_aeae8ba867.jpg" alt="The cookies are in line, your navigation should be too!" width="300" /><br /><small>Photo courtesy of <a href="http://www.flickr.com/photos/phuson/">Phu Son Nguyen</a></small></div>
<p>Last week, we discussed the super-cool <a href="http://siriusgraphix.com/html-navigation">wp_list_pages($args) function</a>, and how it can make creating your navigation on your website super easy.  If you want your navigation in your sidebar, for example, or anywhere else as a vertical list, then this already works perfectly.  But what if you want it as a part of your header, like we do, in a horizontal list?  Don&#8217;t worry, CSS is here to the rescue!</p>
<p><strong>display: inline</strong></p>
<p>First things first, you need a way to identify your list.  While you want your navigation list to have a certain style, you&#8217;re most likely not going to want every single list on your website to have that same style.  It&#8217;d be a bit weird to have horizontal lists when you want to list something in a blog post, don&#8217;t you think?  So we surround the list with a &lt;div> element, and <a href="http://siriusgraphix.com/html-a-classy-identity">put an id on that &lt;div></a>.  Let&#8217;s call it &#8220;navigation&#8221;.  (Remember that <a href="http://siriusgraphix.com/to-table-or-not-to-table-that-is-the-question">we use &lt;div>s &#8211; not tables! &#8211; to divide up the sections of our page</a>.  The navigation is just one little section of the page&#8230; and <a href="http://siriusgraphix.com/html-an-intro-to-headers">we did the same for the header</a>, so you have a larger &lt;div> that encompasses your navigation, and everything else in the header, as well.)</p>
<p>Now that we have a way to identify our navigation list, we can use CSS to make it look exactly how we want it to.</p>
<p>So in order to make our navigation horizontal, all we have to do is add this attribute to the element in the CSS:<code>display:inline;</code> That will make the list show up all in a line, rather than each above the next.  But where do we put it?</p>
<p><strong>Cookie Crumbs</strong></p>
<p>Should we put it on the #navigation?  Nope.  You see, it means nothing to tell your &lt;div> (which is the element that the #navigation id is on) to display inline.  Because a &lt;div> doesn&#8217;t have anything that it <em>can</em> display inline.  It&#8217;s just a way to divvy up our page, after all.</p>
<p>No&#8230; we have to look inside the &lt;div>.  So what&#8217;s next?  Our &lt;ul> element.  Is that where we want to put the display:inline;?  Again, no.  That would just tell the list as a <em>whole</em> to display in a line, which does just about as much good as telling the &lt;div> to do that.  In other words, it doesn&#8217;t do a thing for us.  What we really want is to tell each of the items in a list to display in a line, right?</p>
<p>So&#8230; you guessed it, we want to put the display:inline; attribute on the &lt;li> elements!  We&#8217;ve got a bunch of them, and we want them to all stand nicely in a line, not piling on top of one another&#8217;s head like we normally would.</p>
<p>But there&#8217;s no id or class on the &lt;li> elements in our code.  How on earth are we supposed to do anything in CSS without them?  It&#8217;s easier than you think, I promise.  All you have to do is this: <code>#navigation ul li { display: inline; }</code> It&#8217;s like a path of cookie crumbs&#8230; from your id or class, you just step in through the levels until you get to the element that you want to style.</p>
<p>That&#8217;s all you have to do to get a horizontal navigation.  Easy as can be.</p>
<p><strong>Party Time!</strong></p>
<p>There&#8217;s so much more I can teach you, just about navigation alone!  But&#8230; well&#8230; <a href="http://twitter.com/SiriusGraphix/">Deb</a> and <a href="http://twitter.com/wendikelly/">Wendi</a> are probably already frowning at me for writing a post while I&#8217;m supposed to be on vacation&#8230; (*innocent look*)&#8230; and it&#8217;s Wendi&#8217;s birthday (*even more of an innocent look*) so as much fun as it is to talk about code, we <em>really</em> should be partying, right?</p>
<p>So instead I&#8217;ll just break out the balloons and confetti, and save the rest of all that I&#8217;d <em>love</em> to tell you about navigation until next week!</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/htmlcss-navigation-all-your-cookies-in-a-row/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HTML: Navigation</title>
		<link>http://siriusgraphix.com/html-navigation</link>
		<comments>http://siriusgraphix.com/html-navigation#comments</comments>
		<pubDate>Thu, 08 Apr 2010 12:00:17 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1309</guid>
		<description><![CDATA[Last week, in my Sirius-ly awesome coding series on Sirius, we discussed headers. More specifically, we discussed how to put a gorgeous logo onto your header, using the background attribute in CSS. It&#8217;s a wonderful start, but there&#8217;s far more to headers than that, you know. For example, navigation. Although some people put their navigation [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, in my Sirius-ly awesome coding series on Sirius, we discussed headers.  More specifically, we discussed <a href="http://siriusgraphix.com/html-an-intro-to-headers">how to put a gorgeous logo onto your header, using the background attribute in CSS.</a>  It&#8217;s a wonderful start, but there&#8217;s far more to headers than that, you know.  For example, navigation.  Although some people put their navigation in the sidebar, the majority of websites have the main navigation as part of the header.</p>
<p><strong>GPS (Blog) Navigation</strong></p>
<p>In order to have something to navigate through, you need to have different pages on your website, right?  So you go into the wp-admin section of your WordPress website, like you would when you write a blog post.  Create a new page&#8230; (not post!  There&#8217;s a difference&#8230; posts are what dynamically go on your blog, whereas pages are static &#8211; like your About page, or Contact page, that are always there and pretty much stay the same.)</p>
<p>Once you&#8217;ve created several pages, you&#8217;ll want them in your navigation, right?  So how do you do this?  Well, if you wanted, you could hand code the link to each page into the navigation section of your website.  However, this would mean that whenever you add a new page to your website, you will need to remember to update it in your code.  Which just makes more work for you.  Silly, right?  Especially when we have&#8230; *superhero music*&#8230; the glory of PHP and WordPress!</p>
<p>Ahem.  Got a little overexcited there.</p>
<p>But you <em>should</em> be excited!  You see, WordPress has created a <a href="http://siriusgraphix.com/php-getting-functional">PHP function</a> (yep, they wrote the function <em>for</em> you!  Aren&#8217;t they wonderful?) that takes all of the pages in your website, and outputs them into a neat little list, HTML and all.  This function is called <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">wp_list_pages($args)</a>, and takes in an array of arguments ($args is the <a href="http://siriusgraphix.com/php-getting-functional">parameter</a>) that customize your list of pages.  All of these arguments are explained in detail in the <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">WordPress Codex</a> (the place where all of the WordPress functions are documented and explained)&#8230; but if you have questions about any of them, you&#8217;re always free to ask me in the comments, or even <a href="http://siriusgraphix.com/contact">contact us</a> if you&#8217;re too shy to ask publicly.</p>
<p>We don&#8217;t bite.  Promise.</p>
<p><strong>Making a List, Checking it Twice</strong></p>
<p>As I said before, the wp_list_pages($args) function gives us back a list of the pages on your blog.  But what does that mean, in HTML terms?  It means that the functions gives you back something like this:<code>&lt;li>&lt;a href="http://siriusgraphix.com/services">Services&lt;/a>&lt;/li><br />
&lt;li>&lt;a href="http://siriusgraphix.com/about">About&lt;/a>&lt;/li><br />
&lt;li>&lt;a href="http://siriusgraphix.com/contact">Contact&lt;/a>&lt;/li><br />
&lt;li>&lt;a href="http://siriusgraphix.com/archive">Archive&lt;/a>&lt;/li></code> Seems good, right?  Each &lt;li>&lt;/li> is a <em>list item</em>.  (And each &lt;a href=&#8221;">&lt;/a> is a link &#8211; the url between the quotes after the href is the url that the link points to, and the text between the &lt;a> tags is the text that displays when your browser parses the link like this: &lt;a href=&#8221;http://siriusgraphix.com/&#8221;>Sirius Graphix&lt;/a> displays as <a href="http://siriusgraphix.com/">Sirius Graphix</a>.)</p>
<p>That all seems fine and dandy.  However&#8230; we may have our list items, but our list is not complete.  Not yet, anyways.  You see, there are two different kinds of lists.  You have ordered lists that are numbered, like this:</p>
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
<p>and you have unordered lists, that just use some sort of bullet point without indicating any sort of order, like this:</p>
<ul>
<li>Deb</li>
<li>Wendi</li>
<li>Rose</li>
<li>Allison</li>
<li>Son</li>
</ul>
<p>Because there are two different kinds of lists, you have to differentiate them in your HTML code.  If you want an ordered list, then surround your list items with &lt;ol>&lt;/ol>:<code>&lt;ol><br />
	<span class="tab">&lt;li>One&lt;/li><br />
	&lt;li>Two&lt;/li><br />
	&lt;li>Three&lt;/li></span><br />
&lt;/ol></code> Similarly, if you want an unordered list, then surround your list items with &lt;ul>&lt;/ul>:<code>&lt;ul><br />
	<span class="tab">&lt;li>Deb&lt;/li><br />
	&lt;li>Wendi&lt;/li><br />
	&lt;li>Rose&lt;/li><br />
	&lt;li>Allison&lt;/li><br />
	&lt;li>Son&lt;/li></span><br />
&lt;/ul></code> Easy, right?  Sure it is!</p>
<p>So.  Since the wp_list_pages($args) function only returns the list items, we need to define what sort of list it is.  If you wanted, you could very well make it either an ordered or unordered list &#8211; it&#8217;s up to you!  But 99.99% of the time, you&#8217;re going to want to use an unordered list&#8230; it&#8217;s easy enough to get rid of the bullet points if you don&#8217;t want them, but it&#8217;s kind of silly to number your navigation when those numbers don&#8217;t really mean anything, and just clutter up your navigation.</p>
<p>Since almost everyone uses unordered lists for their navigation, it seems like it would make sense for wp_list_pages($args) to just return the entire list, &lt;ul> tags and all, right?  However, it&#8217;s actually better that they don&#8217;t.  What if you wanted to add a link to an external page into your navigation&#8230; like <a href="http://lifeslittleinspirations.com/">Life&#8217;s Little Inspirations</a> or <a href="http://sayanouchi.com/">Saya No Uchi</a>?  You could just do this:<code>&lt;ul><br />
	<span class="tab">&lt;?php wp_list_pages(); ?><br />
	&lt;li>&lt;a href="http://lifeslittleinspirations.com/">Life's Little Inspirations&lt;/a>&lt;/li><br />
	&lt;li>&lt;a href="http://sayanouchi.com/">Saya No Uchi&lt;/a>&lt;/li></span><br />
&lt;ul></code></p>
<p><strong>Abracadabra!</strong></p>
<p>This is a nice beginning, but there&#8217;s still a lot more to talk about regarding the navigation section of your header, and how to use CSS to make it look great.  After all, wp_list_pages($args) just outputs a list&#8230; a <em>vertical</em> list of items.  But if you want your navigation to be horizontal like how we have it&#8230; you&#8217;re going to have to do a little CSS magic.</p>
<p>So come back next week, and don&#8217;t forget to pack your magic wands&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/html-navigation/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML: An Intro To Headers</title>
		<link>http://siriusgraphix.com/html-an-intro-to-headers</link>
		<comments>http://siriusgraphix.com/html-an-intro-to-headers#comments</comments>
		<pubDate>Thu, 01 Apr 2010 12:00:05 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/html-an-intro-to-headers</guid>
		<description><![CDATA[So you want to start putting together a website. Where do you start? Well, at the top, of course. The first thing anyone ever sees on your website is your header &#8211; so you want it to be great. What goes into a good header? A good design, for one thing. A great logo, some [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to start putting together a website.  Where do you start?  Well, at the top, of course.  The first thing anyone ever sees on your website is your header &#8211; so you want it to be great.</p>
<p>What goes into a good header?  A good design, for one thing.  A great logo, some nice fonts&#8230; a header that sets the tone for the rest of your website.  But <a href="http://siriusgraphix.com/contact">Deb&#8217;s the one to talk to</a> if you&#8217;re interested in design.  That&#8217;s not what I&#8217;m here for.  The other important part of your header is the code &#8211; what makes your header actually <em>work</em>.  And if you want to talk code&#8230; you know I&#8217;m your gal.</p>
<p><strong>Head&#8230; Header&#8230; There&#8217;s a Difference, You Know</strong></p>
<p>We&#8217;ve already discussed <a href="http://siriusgraphix.com/html-getting-inside-your-head">what goes in the &lt;head> section of your website</a>.  And you know by now, that the &lt;head> is <em>not</em> the same thing as the header.  However, when you&#8217;re putting together your php files for your website, 99.99% of the time you&#8217;ll find the <em>&lt;head></em> of the website inside of the <em>header</em>.php file.  It makes sense, right?  The header.php file displays what&#8217;s at the top of every webpage, the &lt;head> section is at the top of every webpage&#8230; so you might as well throw them together.</p>
<p>So you&#8217;ve got the <a href="http://siriusgraphix.com/html-lets-take-it-from-the-top-people">doctype declaration</a> up top, then <a href="http://siriusgraphix.com/html-keep-a-good-head-on-your-shoulders">the entire &lt;head> section</a>&#8230; and after that &lt;/head> closing tag, the &lt;body> section of your website begins.  This is where your header code starts.</p>
<p><strong>Body First</strong></p>
<p>So what comprises a header?  Well, before it even starts, you have the opening &lt;body> tag.  <em>Everything</em> you see on your website is going to be inside of the <a href="http://www.w3schools.com/tags/tag_body.asp">body tag</a>.  So if there are CSS styles that you want on the <em>entire</em> website, then you can set them in your style.css file on the body tag, like this:<code>body { background-color: #c0c0c0; }</code> This just sets the background color of the body tag to #c0c0c0 (that&#8217;s the <a href="http://www.w3schools.com/css/css_colors.asp">hexadecimal code</a> for grey &#8211; more often than not, you will see hexadecimal codes used to refer to different colors on websites).  Similar to how it is in PHP, you always need that semicolon at the end of each attribute, as well as the colon after the attribute name.  Here the attribute name is <a href="http://www.w3schools.com/css/pr_background-color.asp">&#8216;background-color&#8217;</a>, and the attribute value is &#8216;#c0c0c0&#8242;.  And since the &lt;body> tag encompasses <em>everything</em> in your website, then the entire background will be set to gray.  Think of it like your first coat of paint &#8211; you can add more paint on top of it, but the bottom layer will always be that color.</p>
<p><strong>Backgrounds Are Important Too, You Know</strong></p>
<p>Once you&#8217;re inside your &lt;body> tag, what&#8217;s next?  Well, let&#8217;s take a look at the header here on <a href="http://siriusgraphix.com/">Sirius Graphix</a>.  If you look up top, you see that the first thing you see is the logo.  There are a few things to take note of, regarding our logo.  First of all, it&#8217;s really damn gorgeous.  *nods*  Yep.  Heh&#8230; but we&#8217;re supposed to be talking about code here, aren&#8217;t we, instead of Deb&#8217;s beautiful designs.  *shameless grin*</p>
<p>First thing to note is that the logo is a link.  That&#8217;s right, the entire logo.  You can click anywhere on it, and it&#8217;ll take you to <a href="http://siriusgraphix.com/">Sirius Graphix&#8217;s homepage</a>.  (Wait!  Come back!  There&#8217;s still more to talk about!)  Second thing to look at is the image itself &#8211; no matter how big you make your browser, even if it spans the entire Vegas strip, the image will still go across the entire page &#8211; without getting all stretched out of shape.  (Er, not that I&#8217;ve ever tried this.  But it sounds nice.  And hypothetically, it <em>should</em> work&#8230;)</p>
</p>
<p>But how do you get the image there in the first place?  More often than not, especially if you have a fancy header like ours, you&#8217;re going to want to use a <a href="http://www.w3schools.com/tags/tag_div.asp">&lt;div> element</a>, and put an id on it.  (Need a quick refresher course?  Go back and check out my post all about <a href="http://siriusgraphix.com/html-a-classy-identity">ids and classes</a>.)  Let&#8217;s call this id &#8220;header&#8221;.  So it ends up looking like this:<code>&lt;body><br />
<span class="tab">&lt;div id="header">&lt;/div></span><br />
&lt;/body></code> Now that&#8217;s great and all, but how do you use it to put in a header image?  Why, CSS, of course.  Yup, we use a background attribute again.  But this time we&#8217;re referencing the id, not the tag name &#8211; it would be silly to reference &#8216;div&#8217;, because we&#8217;re going to end up with so many &lt;div> elements in our code that our CSS isn&#8217;t going to have the faintest idea which one we meant, and therefore put the style on <em>all</em> of them.  Which is certainly not something we want, at least not in this case.  Nope, instead we use the id name, like this:<code> #header { background: transparent url(images/header.jpg) no-repeat 0 0; }</code> Hm.  That looks kind of similar to the background that we put on the body&#8230; but there are a lot of differences.</p>
<p>First off, it just says &#8216;background&#8217;, not &#8216;background-color&#8217;.  This is because we&#8217;re setting more than just the color.  Where it says &#8216;transparent&#8217;&#8230; <em>that&#8217;s</em> the color.  We could very well have put #c0c0c0 in there, or whatever color we&#8217;d like.  But if we want the possibility of the layers of paint beneath the background to shine through (which certainly does happen, sometimes), then it&#8217;s better to just make it &#8216;transparent&#8217;.  And sometimes you do want a different color on the background, and want to set it there instead of writing &#8216;transparent&#8217;&#8230; and that&#8217;s fine too.</p>
<p>Then it says url(images/header.jpg).  It&#8217;s still part of the &#8216;background&#8217; attribute, because we haven&#8217;t seen a semicolon yet.  This tells your browser where to find the image that you want to use for your background.  Usually in most WordPress themes, there&#8217;s going to be a folder inside of your theme called &#8216;images&#8217;, which is where every image you use in your theme should go.  That way you can always use the path &#8216;images/imageName&#8217; to tell the browser where your image is.  (And don&#8217;t forget the extension!  &#8216;.jpg&#8217;, &#8216;.png&#8217;, &#8216;.gif&#8217;&#8230; there are different situations for each, but you&#8217;ll probably see at least &#8216;.jpg&#8217; and &#8216;.png&#8217; images in your theme.)</p>
<p>Next, you tell the browser how that image should repeat.  I used &#8216;no-repeat&#8217;, since I don&#8217;t want a tile that says &#8220;Sirius Graphix&#8221; repeating itself across the page.  (I only want that logo image once, you see.)  But if you <em>do</em> want it to repeat, you can use &#8216;repeat-x&#8217;, &#8216;repeat-y&#8217;, or &#8216;repeat&#8217;.  Remember in high school math class, where the x-axis was the horizontal one, and the y-axis was the vertical one?  It&#8217;s the same here.  If you want an image to repeat horizontally you say &#8216;repeat-x&#8217;, and if you want it to repeat vertically then you set it to &#8216;repeat-y&#8217;.  And if you want it to repeat both horizontally <em>and</em> vertically, then you just say &#8216;repeat&#8217;.</p>
<p>The last part of the background has to do with positioning.  For my background, you see that I wrote &#8217;0 0&#8242;.  Think about graphs once again, and you remember that (0, 0) was the origin.  This is the same, except 0 0 is the top left-hand corner of your div.  (For you math nerds, that would put us in the fourth quadrant, if I remember correctly.)  Sometimes you&#8217;ll see values like &#8216;center center&#8217;, or &#8216;left top&#8217;&#8230; these do the same thing, except aren&#8217;t quite as exact.  If you needed your background to be a little lower than how it started out, for example, then you could write &#8217;0 10px&#8217; (Don&#8217;t forget the px!  Otherwise it won&#8217;t work right.), or if you wanted it slightly to the right, then do (5px 0).  Or any combination of the two.</p>
<p>When you&#8217;re setting the background attribute in CSS, remember that it always must go in this order: color, image url, repeat, position.  If you mix things up, it&#8217;s very possible that your browser will get confused.</p>
<p><strong>Little By Little</strong></p>
<p>I think that&#8217;s enough for one day, wouldn&#8217;t you agree?  It doesn&#8217;t seem like much &#8211; after all, we only really talked about backgrounds.  But it&#8217;s quite important, and very useful.  I use backgrounds <em>all</em> the time, and sometimes even for uses that you might not even think to use them for!  They&#8217;re very, very handy.</p>
<p>So now that I&#8217;ve given you a little taste of what goes into a header &#8211; an appetizer, if you will &#8211; next week, we start in on the main course.  After all, you don&#8217;t <em>really</em> think that I&#8217;m so mean that I would tell you about how our entire header is a link, or how it spans the <em>entire</em> page no matter how big, and not tell you how to do it yourself, do you?</p>
<p>No, of course not.  But you&#8217;re still going to have to come back next week if you want to find out.</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/html-an-intro-to-headers/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML: Head(er), Shoulders, Knees, and Toes&#8230;</title>
		<link>http://siriusgraphix.com/html-header-shoulders-knees-and-toes</link>
		<comments>http://siriusgraphix.com/html-header-shoulders-knees-and-toes#comments</comments>
		<pubDate>Thu, 25 Mar 2010 12:00:27 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1218</guid>
		<description><![CDATA[For the last two months we&#8217;ve been talking about PHP. The month before that, we discussed tables, ids, classes, and other rules and concepts that are important for developing a website  theme. All of that is important, very much so. You couldn&#8217;t develop a website without it. However, what I have not yet explained is [...]]]></description>
			<content:encoded><![CDATA[<p>For the last two months we&#8217;ve been talking about PHP.  The month before that, we discussed tables, ids, classes, and other rules and concepts that are important for developing a website  theme.</p>
<p>All of that is important, very much so.  You couldn&#8217;t develop a website without it.  However, what I have not yet explained is the actual body of the website &#8211; the part of the code that tells the browser what it&#8217;s supposed to show people who visit your website.  Everything else is important, true, but this is the most important part of all.</p>
<p>And, well&#8230; to have a great website, you need a great body.  Er&#8230; <em>&lt;body&gt;</em>.  So in website terms&#8230; what makes up a good body?</p>
<p><strong>Header</strong></p>
<p>Note that the <em>header</em> is completely different from the <em>head</em> of your website.  The <em>head</em> goes at the <a href="http://siriusgraphix.com/html-keep-a-good-head-on-your-shoulders">very top of your code</a> (right after the <a href="http://siriusgraphix.com/html-lets-take-it-from-the-top-people">doctype declaration</a>), and includes stuff like <a href="http://siriusgraphix.com/html-getting-inside-your-head">links to your CSS and JavaScript files, metadata, and other information about your website</a>.  None of which is actually displayed.</p>
<p>The <em>header</em>, on the other hand, <em>is</em> displayed.  It&#8217;s what you see at the very top of just about every website out there.  Here on <a href="http://siriusgraphix.com/">Sirius Graphix</a>, our header consists of our logo, our navigation bar, and that neat gold slider.  It&#8217;s exactly the same on every single page within our website.</p>
<p>Because the header is the same on every page in our website (and this holds true for most websites out there), we can use a single header.php file (go look!  More likely than not, there&#8217;s already a header.php file in your theme) and just include it on every page we make in the website.  Convenient, isn&#8217;t it?</p>
<p><strong>Footer</strong></p>
<p>As the name suggests, the footer goes at the foot &#8211; or at the bottom &#8211; of your website.  As with the header, most footers are exactly the same on all pages &#8211; they usually include copyright information, sometimes an abridged version of the navigation, and can include other information such as who developed your website.  (You had <a href="http://siriusgraphix.com/about">us</a> do it, right?  We&#8217;re <a href="http://siriusgraphix.com/services">real good at these sorts of things</a>.  <a href="http://siriusgraphix.com/contact">Just ask</a>!)  And, as with the header, since it&#8217;s the same on every page in your website, you can just use one footer.php file, and include it on every page.  Easy peasy.</p>
<p><strong>Sidebar</strong></p>
<p>The sidebar goes &#8211; you guessed it &#8211; at the side of your website.  Now here&#8217;s where it gets a tiny bit more complicated.  But don&#8217;t be scared.  We can handle this.</p>
<p>The easiest scenario is when you have one sidebar that stays exactly the same on all pages.  In this case, all you have to do is include a single sidebar.php file, just like with the header and footer.  (Actually, that&#8217;s a lie.  The very easiest scenario is when you don&#8217;t have a sidebar at all.  But in that case, this section about sidebars doesn&#8217;t even matter, right?)</p>
<p>But then there are the cases when you have different sidebars depending on what page you&#8217;re on, or two sidebars next to each other, or one sidebar on either side of the content&#8230; this is where it gets a little more involved.  In some of these cases, you&#8217;re even going to have to have multiple files for the sidebar.</p>
<p>But not to fear!  I am here&#8230; and I am here for you.  In upcoming weeks as we go through the body section of WordPress themes, I will explain this, <em>all</em> of this, and by the end of it you&#8217;ll be able to create sidebars like a pro.</p>
<p><strong>Content</strong></p>
<p>Unlike the header, footer, and even the sidebar, your content section is going to be different on every page of your website.  I mean it.  Every single page of your website is going to have different content.  (Because why on earth would you want two pages to look exactly alike?  That&#8217;s just silly.  Not to mention redundant and kind of pointless.)</p>
<p>So does this mean you have to have a different file for every single page on your website, since they all have different content?  (If you have a blog, this can number into the hundreds, or even thousands.)</p>
<p>No, not at all.</p>
<p><em>*big sigh of relief*</em></p>
<p>You see, although the content on every page is going to be different, many of the pages have the same format.  Take your blog posts, for example.  Generally, blog posts consist of a title, the date it was posted, the author&#8217;s name, the actual post itself (consisting of words and pictures, usually), metadata, comments, and a comment form.  And maybe some social media buttons and links to similar posts.</p>
<p>Every website is different, but within a website, every single blog post is going to consist of the same elements.  So really all we have to do is make one .php file (usually single.php in your WordPress themes) that sets up the format for the blog post pages&#8230; and voila, all that&#8217;s left to do is insert the content for that particular blog post!  Which is super duper easy.  You won&#8217;t even break a sweat doing it.  And&#8230; *drum roll, please*&#8230; you use PHP to insert the content, so <em>you</em> don&#8217;t even have to know which post the user is looking at!  Your server does all the work for you.  Ain&#8217;t it great?</p>
<p>Then there are other pages, like your About page (super duper easy), Archives page (easy), Contact page (a little harder, but plugins can help with this!), Shop page (also something plugins can make much easier&#8230; woo!), etc., etc&#8230;. depending on what&#8217;s in your pages, you can use the basic page.php template (like for the About page), or you can create additional templates that fit the format of your other pages.  For example, here on Sirius we have one for our Archives page and another for our Contact page, since their styles are fairly different from our basic pages.</p>
<p><strong> </strong></p>
<p>So there you have it, everything that makes up a WordPress theme!</p>
<p>Well&#8230; sort of.  The rough outline, at least.</p>
<p>Next week, we <em>really</em> start discussing what makes up a website, as we look at all that comprises the header (not head!  <a href="http://siriusgraphix.com/html-getting-inside-your-head">We already did that!</a>) section of your website.</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/html-header-shoulders-knees-and-toes/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Wrapping Things Up</title>
		<link>http://siriusgraphix.com/php-wrapping-things-up</link>
		<comments>http://siriusgraphix.com/php-wrapping-things-up#comments</comments>
		<pubDate>Thu, 18 Mar 2010 11:00:38 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1174</guid>
		<description><![CDATA[If you&#8217;ve been reading my posts about coding the last few weeks, then you&#8217;re pretty much ready to deal with any of the PHP that you come across in a WordPress theme. Heck, maybe you&#8217;re even ready to write your own PHP! I&#8217;m so proud&#8230; you&#8217;re all such good students. But before we move on [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been reading <a href="http://siriusgraphix.com/author/sushi">my posts about coding</a> the last few weeks, then you&#8217;re pretty much ready to deal with any of the PHP that you come across in a WordPress theme.  Heck, maybe you&#8217;re even ready to write your own PHP!  I&#8217;m so proud&#8230; you&#8217;re all such good students.</p>
<p>But before we move on to the next part of your theme &#8211; the actual HTML in the body that displays what you see on your website &#8211; there are a few last things to wrap up regarding PHP.</p>
<p><strong>Operators</strong></p>
<p>There&#8217;s one last thing that we haven&#8217;t discussed much in PHP, that you&#8217;re guaranteed to see in almost any PHP code out there.  Operators.  It might seem like we&#8217;re taking a step back into middle school math, but this will be painless.  I promise.</p>
<p>First, we have the <a href="http://www.php.net/manual/en/language.operators.arithmetic.php">arithmetic operators</a>: +, -, /, *, %.  These do exactly what you&#8217;d expect: add, subtract, divide, multiply, and take the modulus (the remainder of one number divided by another.  5 % 2 is 1).  You can also negate a value by putting &#8211; in front of it.  Easy.</p>
<p>Then, there are the <a href="http://www.php.net/manual/en/language.operators.assignment.php">assignment operators</a>.  = is obvious, you&#8217;re just setting one value equal to another, like this: $a = 5.  Then there&#8217;s += which means that you add the value to the variable.  So $a += 2 would be 7, because we already set $a to 5.  That works for numbers, but what about strings?  Here you use .= which tells you to concatenate one string onto the end of other.  Pretty much just sticking them together.  So if we started with $b = &#8216;Hello &#8216;; and then did $b .= &#8216;world!&#8217;; $b would end up as &#8216;Hello world!&#8217;.  You do something similar if you want to stick a variable in the middle of a string.  You could just do $c = $b . &#8221; What&#8217;s up?&#8221;; and it would show up as &#8220;Hello world! What&#8217;s up?&#8221;  (Notice that I used double quotes to surround the string there.  Since we had an apostrophe in &#8220;what&#8217;s&#8221;, I didn&#8217;t want it to be read as a closing single quote, which would screw things up.  Luckily, in PHP you can just use double quotes instead, and avoid that problem.)</p>
<p>Next are the <a href="http://www.php.net/manual/en/language.operators.comparison.php">comparison operators</a>.  We already know that = sets a variable equal to a value.  But what if we want to test to see if two things are equal?  We definitely don&#8217;t want to set the variable equal to the value we&#8217;re testing for.  That would be bad.  So instead we use == or ===.  $a == $b will be true if $a is equal to $b.  $a === $b is the same, but also adds the constraint that $a and $b have to be the same type.  (But why?  Well, what if you wanted to test to see if $a is equal to the boolean value <em>true</em>?  If $a is any non-zero, non-null value, then when you translate it to boolean it shows up as <em>true</em>.  But that&#8217;s not what we want.  So instead we&#8217;d use === to say that it&#8217;s only true if $a is the boolean value <em>true</em>, and if it&#8217;s not boolean, then it&#8217;ll show up as false.)  Then we have != which tests to see if two values are not equal, and !== to see if two values are either not equal or not of the same type.  The opposite of == and ===, if you will.  The other four comparison operators should be familiar from your old math classes: <, >, <=, >= simply test to see if one value is less than, greater than, less than or equal to, or greater than or equal to another.</p>
<p>Then there are the <a href="http://www.php.net/manual/en/language.operators.increment.php">incrementing and decrementing operators</a>.  ++ increments (adds 1 to) a variable.  &#8211; - decrements (subtracts 1 from) a variable.  Put it beforehand if you want to increment/decrement before the value is returned (if you start with $a = 1, echo ++$a; will print out &#8217;2&#8242;).  Put it afterward if you want to increment/decrement after the value is returned (if you start with $a = 1, echo $a++; will print out &#8217;1&#8242;, and then if you echo $a; after that, it will print out &#8217;2&#8242;).</p>
<p>Next we have <a href="http://www.php.net/manual/en/language.operators.logical.php">logical operators</a>.  We&#8217;ve already talked about &#038;&#038; and ||&#8230; ($a &#038;&#038; $b) means that both $a and $b have to be true in order for the entire expression to be true, and ($a || $b) means that either $a or $b or both have to be true for the expression to be true.  (You can also use &#8216;and&#8217; instead of &#8216;&#038;&#038;&#8217;, and &#8216;or&#8217; instead of &#8216;||&#8217;.)  If you want either $a or $b to have to be true, but NOT both to have to be true, then you can use $a xor $b.  Lastly we have !, which means not.  (!$a) means that $a has to be false for the expression to be true.  Make sense?</p>
<p><strong>Teacher, Teacher, I Have A Question</strong></p>
<p>Now that we&#8217;ve explained the basis of PHP for you, where can you go to find more information?</p>
<p>Well, you can always come back here, of course.  For now I&#8217;m moving on to talk about HTML, CSS, and JavaScript, but you can be sure there will be more posts about PHP in the future as well.</p>
<p><a href="http://php.net/">PHP.net</a> is an excellent resource.  Any time you ever have to look up a <a href="http://siriusgraphix.com/php-getting-functional">function</a> that you (or your web developer) didn&#8217;t create on your own, chances are you&#8217;ll find the documentation for it here.  And it goes the other way around too &#8211; whenever you need to figure out how to do something (for example, what if you want to display today&#8217;s date?  or change a string to all lowercase?) you can do a search for it, and 90% of the time you&#8217;ll find a pre-made function that does exactly what you need, on PHP.net.  And while you&#8217;re there, check out the comments on every page &#8211; there you&#8217;ll find discussion and examples about how other programmers have used these functions.</p>
<p><a href="http://www.w3schools.com/php/default.asp">w3schools.com</a> is another great resource.  While PHP.net is all about documentation, w3schools.com tends more towards tutorials and examples how to use things.</p>
<p>If you want to purchase a book about PHP, <a href="http://www.amazon.com/gp/product/0596006306?ie=UTF8&#038;tag=sush-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596006306">Head First PHP &#038; MySQL</a> is an excellent resource.  I love the Head First series for learning any sort of programming language &#8211; they explain things in ways that are very easy to understand, and even have games at the end of every chapter to help you remember what you learned.  I have a couple of the Head First books from back when I was first learning, and I can definitely vouch for how helpful and easy to use they are.</p>
<p><strong>I Am Here For You!</strong></p>
<p>If there&#8217;s anything else &#8211; anything at all &#8211; you want to know about PHP, or coding in general, just ask!  Even if it&#8217;s something that can be found in any of those references, I&#8217;m always happy to help.  Whether it&#8217;s something confusing from the code in your theme, or questions about different web technologies, or anything else coding- or tech-related, I&#8217;m here for you.  Really.  I want to help you guys.  And maybe you&#8217;ll even get a blog post written specifically to answer your question!</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/php-wrapping-things-up/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP: Real Code, And A Game Of Hangman</title>
		<link>http://siriusgraphix.com/php-real-code-and-a-game-of-hangman</link>
		<comments>http://siriusgraphix.com/php-real-code-and-a-game-of-hangman#comments</comments>
		<pubDate>Thu, 11 Mar 2010 12:00:50 +0000</pubDate>
		<dc:creator>Allison Day</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://siriusgraphix.com/?p=1142</guid>
		<description><![CDATA[Photo courtesy of Phu Son Nguyen I&#8217;m such a tease. For the last two weeks, I&#8217;ve been tempting you with a game of hangman, promising you real PHP code that actually works&#8230; none of that silly pseudo-code business. Can you blame me? I&#8217;ve got to keep you all coming back somehow&#8230; Well. Today, I tease [...]]]></description>
			<content:encoded><![CDATA[<div class="alignright"><img class="alignright" title="Hangman" src="http://farm5.static.flickr.com/4005/4423969849_5161bbf990.jpg" alt="Hangman" width="300" /><br /><small>Photo courtesy of <a href="http://www.flickr.com/photos/phuson/">Phu Son Nguyen</a></small></div>
<p>I&#8217;m such a tease.  For the last <a href="http://siriusgraphix.com/php-getting-loopy">two</a> <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">weeks</a>, I&#8217;ve been tempting you with a game of hangman, promising you real PHP code that actually works&#8230; none of that silly pseudo-code business.  Can you blame me?  I&#8217;ve got to keep you all coming back somehow&#8230;</p>
<p>Well.  Today, I tease no more, my friends.  Not only do I have real code for you in today&#8217;s blog post, I actually have code that you can <a href="http://sushiday.com/hangman/hangman.php.zip">download</a>.  For free.  With tons of comments throughout that explain <em>everything</em>.  Yes, I&#8217;m awesome like that.</p>
<p>And, even better, you can actually run this code on your own server (or hop on over to mine), and <a href="http://sushiday.com/hangman/hangman.php">play an real working game (or several) of hangman.</a>  (No, really!  Click the link, it&#8217;s awesome.  And then come back and read the rest of the post.)</p>
<p><strong>THE CODE: the abridged version</strong></p>
<p>If you download the code itself, you&#8217;ll see there are a few things I don&#8217;t talk about today, like <a href="http://www.w3schools.com/php/php_sessions.asp">sessions</a> and <a href="http://www.w3schools.com/tags/tag_form.asp">form HTML</a>.  These are way, way beyond the scope of today&#8217;s post, although I may get to them someday.  But I&#8217;ve tried to leave comments within the code that will explain everything so it&#8217;s not too difficult to understand.</p>
<p>For the purpose of today&#8217;s post, this is the code we&#8217;re looking at, which is really just an excerpt of the code you can download:</p>
<p><code>$word = 'sushi';<br />
if ($guessLength < strlen($word) &#038;&#038; $hangman < 6) {<br />
	<span class="tab">$message = "The game's not over yet...";<br />
	$match = false;<br />
	$guess = [user's guess];<br />
	$positions = array();<br />
	if (in_array($guess, $alreadyGuessed)) {<br />
		<span class="tab">$message = "You already guessed '" . $guess . "'!";<br />
		$isGuessed = true;</span><br />
	}<br />
	if (!$isGuessed &#038;&#038; $guess != null) {<br />
		<span class="tab">$alreadyGuessed[] = $guess;<br />
		for ($j = 0; $j < strlen($word); $j++) {<br />
			<span class="tab">if (strcmp(substr($word, $j, 1), $guess) == 0) {<br />
				<span class="tab">$match = true;<br />
				$positions[] = $j;</span><br />
			}</span><br />
		}<br />
		if ($match == true) {<br />
			<span class="tab">foreach ($positions as $k => $position) {<br />
				<span class="tab">if (strcmp($display[$position], '_') == 0) {<br />
					<span class="tab">$display[$position] = $guess;<br />
					$guessLength++;</span><br />
				}</span><br />
			}</span><br />
		} else {<br />
			<span class="tab">$hangman++;</span><br />
		}</span><br />
	}</span<br />
}<br />
echo $hangman . ' bad guesses.';<br />
foreach ($display as $l => $letter) {<br />
	<span class="tab">echo $letter . ' ';</span><br />
}<br />
echo $message; </code>  Like always, let&#8217;s go through it, line by line.</span></p>
<p><strong>Initial Variables</strong></p>
<p>$word = &#8216;sushi&#8217;;  This one&#8217;s easy.  (Although in the actual game code, it randomly chooses from a list of words instead.)  All you&#8217;re doing is setting your $word variable equal to the value, &#8216;sushi&#8217;.  Sushi has to go in quotes (technically you can use either single quotes: &#8216; &#8216; or double quotes: &#8221; &#8220;) because it&#8217;s a string &#8211; a bunch of characters all put together.</p>
<p>In the actual code, there are a few other variables like $hangman, $guessLength, $alreadyGuessed, $hangmanImage, and $display that are also set, using <a href="http://www.w3schools.com/php/php_sessions.asp">sessions</a>.  For the purpose of today, you don&#8217;t have to know how it&#8217;s done, just know that they&#8217;re there.</p>
<p><strong>The Outer If-Statement</strong></p>
<p>Next, we open the <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a>.  (Yes, it was a while loop in <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">last week&#8217;s pseudo-code</a>.  While hypothetically that works great, since in a true human game it&#8217;s continuous, it doesn&#8217;t work quite so nicely in the computer world.  So we use an <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a> instead.)  Since it&#8217;s an <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a>, we need a condition to test, right?  Here, our condition is actually two conditions, that both must be true.  The first one, $guessLength < strlen($word), says that we're only going to keep playing the game so long as the number of letters that we've guessed right is less than the number of letters in the word.  Because if you think about it, there's no point in continuing to play the game if you've already guessed the entire word, right?</p>
<p>The second condition in the <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a>, $hangman < 6, tells us that we're only going to keep going if there are less than 6 parts in the hangman.  (Head, body, two arms, two legs.)  If the hangman is complete, meaning there are already 6 parts there, then the player has lost the game and we don't want to continue playing.</p>
<p>You see the opening curly brace right after the conditions, but where&#8217;s the closing one?  Remember &#8211; <a href="http://siriusgraphix.com/html-a-few-basic-rules">just like in HTML, your PHP code is like an onion</a>.  So each layer has to completely enclose the layers within it, and be completely enclosed by the layers outside of it.  So the closing curly brace for our <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a> is at the end &#8211; after all the other inner loops have closed.  The indentation makes this simple &#8211; you can easily see the closing brace because it&#8217;s on the same indentation level as the opening one.</p>
<p><strong>Even More If-Statements</strong></p>
<p>Just inside of the outer <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a>, you see a few more statements before your <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">for-loop</a>.  The first is a variable that&#8217;s set to text which we&#8217;ll print out later.  Then two variables: $match which is set to the boolean value false, and $guess which is set to the single letter that the user has guessed.  Super easy.  Making sense so far?</p>
<p>Before you step inside the <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">for-loop</a>, you also create an array called $positions&#8230; but don&#8217;t put anything in it quite yet.  But we will, soon.  Don&#8217;t worry.</p>
<p>Then a couple of <a href="http://siriusgraphix.com/php-on-one-condition">if-statements</a>.  By now, you should be able to make some sense of them.  The first one is simply making sure that the letter isn&#8217;t one you&#8217;ve already guessed, and printing out a message if you have.  And the second one is saying that if you haven&#8217;t guessed the letter and your guess isn&#8217;t blank, then keep going with the code inside.  You put the guess into the array of letters you&#8217;ve already guessed, so you can&#8217;t choose it again&#8230; and then you get to your first <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">for-loop</a>.</p>
<p><strong>Moving On, The For Loop</strong></p>
<p>Next comes your <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">for-loop</a>.  Remember last week, when I explained the code you see here?  Well, this week you see it in action.  We&#8217;re starting at zero ($j = 0;), looping for the length of the word ($j < strlen($word);) and incrementing by one each time you go through the loop.</p>
<p>Then there&#8217;s an <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a>.  It&#8217;s the fourth one you&#8217;ve seen in today&#8217;s code, so you&#8217;re sure to be cool with it by now.  And I know you&#8217;ve seen that <a href="http://php.net/manual/en/function.strcmp.php">strcmp() function</a> before.  So what&#8217;s that <a href="http://php.net/manual/en/function.substr.php">substr() function</a> do?  It takes the sub-string of the string $word, starting at position $j in the string and taking the next 1 letter.  So since our word is &#8216;sushi&#8217;, and if we&#8217;ve looped so $j = 1, substr($word, $j, 1) will be &#8216;u&#8217;.  (&#8220;But why?  Isn&#8217;t the first letter in &#8216;sushi&#8217; &#8216;s&#8217;?&#8221;  Yes, however remember that in programming, you always start at zero.  So the letter at position 0 in &#8216;sushi&#8217; is actually &#8216;s&#8217;, and the letter at position 1 is therefore &#8216;u&#8217;.)</p>
<p>So, <em>if</em> the substring is the same letter as the one the player guessed, then we&#8217;ll say that yes, there is a match &#8211; we&#8217;ll set $match = true;.  In addition, we set $positions[] = $j;.  But wait, what does that mean?  Like the name suggests, the $positions array is an array that tells us which positions in the word have been guessed correctly.  So if our word was &#8216;sushi&#8217;, and the player guessed &#8216;u&#8217;, then we would add $j (which at that point equals 1) to the array.</p>
<p>And we keep looping through the <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">for-loop</a> until we&#8217;ve checked your guess against every letter in the word.</p>
<p><strong>Even Better, A For-Each Loop</strong></p>
<p>Another <a href="http://siriusgraphix.com/php-on-one-condition">if-statement</a>.  Yes, I know, y&#8217;all are experts at <a href="http://siriusgraphix.com/php-on-one-condition">if-statements</a> by now.  I&#8217;m so proud of you.  So we&#8217;ll skip over that, and look at that <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">foreach loop</a>.  All it&#8217;s saying is that for each object in the $positions array, we&#8217;re going to call the key $k, and the value $position.  (Remember that they&#8217;re paired up &#8211; every key matches up with a value.  Like how <a href="http://siriusgraphix.com/html-a-classy-identity">every SSN matches up with a person</a>.)  So that little block of code just says, if the position you&#8217;re looking at still shows up as _, meaning you haven&#8217;t guessed it yet, then put in the guessed letter.  Otherwise, if there isn&#8217;t a match, then add a part to the hangman.</p>
<p><strong>Hold On&#8230; That&#8217;s It?</strong></p>
<p>Yep.  That&#8217;s all.  As you can see, all that&#8217;s left after that are echo statements (and another sneaky but simple <a href="http://siriusgraphix.com/php-for-while-and-other-loopy-things">foreach</a>).  See?  Coding isn&#8217;t so hard now, is it?</p>
]]></content:encoded>
			<wfw:commentRss>http://siriusgraphix.com/php-real-code-and-a-game-of-hangman/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
