<?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>Design, Development, and Consulting &#187; Wordpress</title>
	<atom:link href="http://netlumination.com/blog/category/tutorials/wordpress-posts/feed" rel="self" type="application/rss+xml" />
	<link>http://netlumination.com</link>
	<description>A web design, development, and consulting firm based in Portland, Oregon helping small businesseses and individuals.</description>
	<lastBuildDate>Wed, 01 Sep 2010 23:27:20 +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>Three Steps for Using JQuery in Your WordPress Theme</title>
		<link>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme</link>
		<comments>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme#comments</comments>
		<pubDate>Mon, 31 May 2010 05:58:39 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1202</guid>
		<description><![CDATA[This is a quick post on using Javascript and the JQuery framework in particular within your WordPress theme. It&#8217;s quick and pretty painless. This is just for regular themes, not admin themes, plugins, or posts. Step 1: Load JQuery and your custom JS onto your page with wp_enqueue_script(). It&#8217;s better to use wp_enqueue_script than hard [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick post on using Javascript and the JQuery framework in particular within your WordPress theme. It&#8217;s quick and pretty painless. This is just for regular themes, not admin themes, plugins, or posts.</p>
<p><strong>Step 1:</strong></p>
<p><strong><span id="more-1202"></span></strong></p>
<p>Load JQuery and your custom JS onto your page with wp_enqueue_script(). It&#8217;s better to use wp_enqueue_script than hard coding it into your page. This is because WordPress comes with JQuery, so you won&#8217;t have to worry about updating JQuery as new versions come out. WordPress will do the work for you.  Make sure wp_enqueue script is before wp_head(), or it won&#8217;t work.</p>
<p>Here&#8217;s a snippet from my template file (let&#8217;s say index.php). I&#8217;ve created my custom JQuery functions in my themes &#8220;scripts&#8221; directory with the file name &#8220;custom-js.js&#8221;. You also have to make up a handle or name for your collection of custom JQuery functions. I called mine custom:</p>
<ol>
<li>
<pre>&lt;?php</pre>
</li>
<li>
<pre>    wp_enqueue_script('jquery');</pre>
</li>
<li>
<pre>    wp_enqueue_script('custom', get_bloginfo('stylesheet_directory') . '/scripts/custom-js.js');</pre>
</li>
<li>
<pre>    wp_head(); // WP API Hook</pre>
</li>
<li>
<pre>?&gt;</pre>
</li>
</ol>
<p>get_bloginfo is your friend. If you hard code your themes directory into your code anywhere, you won&#8217;t be able to share it with others, and you&#8217;ll break everything if you ever move hosts or just directories.</p>
<p>Here&#8217;s another example. Let&#8217;s say you want to use <a href="http://code.google.com/apis/maps/documentation/javascript/examples/index.html">Google Maps</a> on your page. Here is the line of WP code that makes that possible:</p>
<ol>
<li>
<pre>&lt;?php</pre>
</li>
<li>
<pre>    wp_enqueue_script('googleMaps', 'http://maps.google.com/maps/api/js?sensor=false');  </pre>
</li>
<li>
<pre>?&gt;</pre>
</li>
</ol>
<p>Finally, if you just want plain JS with no JQuery, you can simply leave out the line that calls JQuery but leave in the line that enqueues your custom functions. WordPress comes with a lot of other JS goodies besides JQuery. Scroll down to<a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script"> the bottom of this page</a> to look at all the other stuff included with WordPress.</p>
<p><strong>Step 2:</strong><br />
Write your JQuery. The only thing you have to look out for is that wp_enqueue_script() calls JQuery in no conflict mode. This means that $ will not work as a shortcut for JQuery functions. There are two simple solutions.</p>
<ol>
<li>Define another shortcut for JQuery functions.</li>
<li>Use a wrapper around your JQuery code.</li>
</ol>
<p>Here is how to define a new shortcut for JQuery functions, $j in this case. The script shown is a very effective test to see if you&#8217;ve got JQuery working in your theme. It&#8217;s a little blunt, but it&#8217;s effects are hard to miss.</p>
<ol>
<li>
<pre>var $j = jQuery.noConflict();</pre>
</li>
<li>
<pre>$j(document).ready(function(){</pre>
</li>
<li>
<pre> $j("body").html("Your page is belong to us... just kidding, but you can use JQuery now.");</pre>
</li>
<li>
<pre>});</pre>
</li>
</ol>
<p>Here is how to use a wrapper in order to use the default JQuery shortcut:</p>
<ol>
<li>
<pre>jQuery(document).ready(function($) {</pre>
</li>
<li>
<pre>    $("body").html("Your page is belong to us... just kidding, but you can use JQuery now.");</pre>
</li>
<li>
<pre>});</pre>
</li>
</ol>
<p>Make sure you pay attention to all the curly brackets and parentheses. If the long and multiple parenthetical expressions annoy you, go check out <a href="http://www.cs.cmu.edu/afs/cs/project/theo-11/www/decision-trees.lisp">Lisp</a>.</p>
<p>Anyway, the second method is nice, since it let&#8217;s you use previously written code easily.</p>
<p><strong>Step 3:</strong></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating your first WordPress theme &#8211; Part 1</title>
		<link>http://netlumination.com/blog/creating-your-first-wordpress-theme-part-1</link>
		<comments>http://netlumination.com/blog/creating-your-first-wordpress-theme-part-1#comments</comments>
		<pubDate>Wed, 26 May 2010 19:26:46 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[convenience]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1041</guid>
		<description><![CDATA[Content Management Systems and WordPress is so powerful because it allows site owners to update their sites efficiently and to customize their sites and their CMS experience. WordPress themes control both the look of a site and the options a site owner has in terms of customizing this look. That sounds pretty good and rather [...]]]></description>
			<content:encoded><![CDATA[<p>Content Management Systems and <a href="http://wordpress.org/">WordPress</a> is so powerful because it allows site owners to update their sites efficiently and to customize their sites and their CMS experience. <a href="http://codex.wordpress.org/Theme_Development">WordPress themes</a> control both the look of a site and the options a site owner has in terms of customizing this look.</p>
<p>That sounds pretty good and rather vague. It&#8217;s hard to describe what you can do with WordPress themes, since they can do a lot. It&#8217;s like trying to describe all the things you can do with a nail. It all depends on how you use it.</p>
<p>In light of this, it seems like the best thing to do would be to go through an example of building a WordPress theme. I&#8217;ll go through a theme as I develop it, and I&#8217;ll try to build it starting at the simplest level and working to progressively more complicated iterations.</p>
<p>Before we begin, there&#8217;s a few things that I&#8217;m going to assume:</p>
<ol>
<li>You&#8217;ve got WordPress installed on your site. <a href="http://codex.wordpress.org/Installing_WordPress">It&#8217;s usually pretty easy to install WordPress</a>.</li>
<li>You can access the files in your WordPress install.</li>
<li>You can access your WordPress admin panel.</li>
</ol>
<p><span id="more-1041"></span></p>
<p>You can usually access your files through FTP, SSH, or even your web host&#8217;s control panel. On Windows I usually use <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> for SSH. I&#8217;ve heard good things about <a href="http://filezilla-project.org/">FileZilla</a> for FTP, but I&#8217;ve personally never tried it. You can edit your files with anything from Notepad (ugh) to <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> (yay!) to <a href="http://www.adobe.com/products/dreamweaver/">Dreamweaver</a> (for all the flack Dreamweaver gets, it sure can speed up a lot of things), <a href="http://www.gnu.org/software/emacs/tour/">Emacs</a> (hang on, let me grow a beard and put on my glasses)&#8230;</p>
<p>Actually, in spite of the beard and glasses joke, if your host offers a Unix or Linux shell, then working on your pages with Emacs can be a great pleasure. I mean you have access to not just your files, but also to your files through one of the most powerful &#8220;word processors&#8221; in the world. No more worrying about whether your files are on your desktop, laptop, smartphone, or smartbrain. Anyway, Emacs is fun and free (free as in hair, and yanking it out in frustration while you pound your head against the keyboard trying to understand what a <a href="http://www.gnu.org/software/emacs/emacs-lisp-intro/elisp/Lambda-Expressions.html#Lambda-Expressions">Lambda expression</a> is). No, but seriously, using Emacs through SSH courtesy of your web host is fantastic stuff, and lets them work a little for the money you give them. I will shamelessly mention that I use <a href="http://www.dreamhost.com/r.cgi?132190">Dreamhost</a>, and so can you by clicking on that link that will earn me money when you sign up.</p>
<p><script type="text/javascript">// <![CDATA[
 google_ad_client = "pub-4166122661117213"; /* 336x280, created 4/27/09 */ google_ad_slot = "9673694336"; google_ad_width = 336; google_ad_height = 280;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<p>Ok, you&#8217;ve got WordPress installed, and you can access the files on your server. Let&#8217;s start building a theme.</p>
<p>The way WordPress works is that it runs a bunch of PHP create the HTML for your web pages. These PHP pages will often look into an associated MySQL database for info. The PHP will also look (ok, I&#8217;m definitely anthropomorphizing) in specific directories for certain things.</p>
<p>One of these special directories contain all the themes that you have installed. Each theme is in its own folder, and you can pick the theme to use through the WordPress admin panel.</p>
<p>You can find the theme choices on the left side of the adminn panel under &#8220;Appearance&#8221;:</p>
<p><img class="alignnone size-full wp-image-1046" title="Wordpress themes" src="http://netlumination.com/wp-content/uploads/2010/05/wp-011.jpg" alt="Themes through the admin panel" width="244" height="436" /></p>
<p>The directory that the themes you can pick from are in is:</p>
<blockquote><p>/wp-content/themes/</p></blockquote>
<p>Each directory in themes is a theme you can use. Understanding how WordPress knows that the contents of these directories are themes will help us create our first theme.</p>
<p>WordPress looks at the main stylesheet in each directory, and from this style sheet it reads the information about the theme. You have to know that convention that for WordPress the main style sheet is a file called, &#8220;style.css&#8221;. So the simplest theme is just a style sheet in a directory. Let&#8217;s see how to make one of these themes&#8230;</p>
<p>Let&#8217;s look at this in practice. Here&#8217;s is what the themes page looks like when /wp-content/themes only has the Classic theme in it. In other words /wp-content/themes only has a directory named &#8220;classic&#8221; in it, and the index.php file:</p>
<p><img class="alignnone size-full wp-image-1056" title="Classic theme" src="http://netlumination.com/wp-content/uploads/2010/05/wp-021.jpg" alt="Classic theme" width="440" height="239" /></p>
<p>As you can see, I&#8217;m currently redoing <a href="http://www.evergreenicesports.org/">Evergreen Ice Sports</a> web page. Soon it&#8217;ll look nicer and be easier to maintain for the site owners. Anyway, as you can see currently Classic is the only available theme.</p>
<p>If we create a directory with only a style sheet called &#8220;style.css&#8221; in it, we can use that style sheet to:</p>
<ol>
<li>Tell WordPress that the directory the style sheet is in contains a WordPress theme.</li>
<li>Tell WordPress that theme is just like another theme with a few modifications (in other words the theme is a <a href="http://codex.wordpress.org/Child_Themes">child theme</a>).</li>
</ol>
<p>Ok, let&#8217;s step through this and then discuss it. First create a directory called, &#8220;mytheme&#8221; in wp-content/themes . Now reload the Manage Themes page in the admin panel to see what happened:</p>
<p><img class="alignnone size-full wp-image-1057" title="Mytheme" src="http://netlumination.com/wp-content/uploads/2010/05/wp-031.jpg" alt="Broken theme" width="440" height="291" /></p>
<p>This shows you that I was telling the truth about WP looking in the wp-content/themes directory for the available themes. It looked in your empty directory called mythemes, and since it the information about each theme is supposed to be in the main style sheet, and there is no style sheet in mythemes, we have a broken theme.</p>
<p>Let&#8217;s add a stylesheet over at wp-content/themes/mytheme/style.css. This style sheet will contain all the necessary information to create a WordPress theme. Here are all of the contents:</p>
<ol>
<li>
<pre>/*</pre>
</li>
<li>
<pre>Theme Name:     My Theme</pre>
</li>
<li>
<pre>Theme URI:      http: //netlumination.com/</pre>
</li>
<li>
<pre>Description:    Child theme spawned by the Classic theme</pre>
</li>
<li>
<pre>Author:         Peter Ajtai</pre>
</li>
<li>
<pre>Author URI:     http: //peter-ajtai.com/</pre>
</li>
<li>
<pre>Template:       classic</pre>
</li>
<li>
<pre>Version:        1.0</pre>
</li>
<li>
<pre>*/</pre>
</li>
</ol>
<p>Yup, that&#8217;s all it takes, and yeah replace my info with your info, but make sure that line 7 stays untouched. The file contains only CSS comments. WordPress, reads these comments, and when it sees line 7, that says &#8220;Template: default&#8221;, it understands that mytheme is a child theme of the theme that is in the directory called, &#8220;classic&#8221;. Let&#8217;s reload the Themes admin panel and activate this new theme.</p>
<p><img class="alignnone size-full wp-image-1058" title="Our style" src="http://netlumination.com/wp-content/uploads/2010/05/wp-041.jpg" alt="Our style" width="440" height="521" /></p>
<p>You can see how WordPress used the information in the CSS file to fill in the information about our new theme. You&#8217;ll notice that there is no screen shot for My Theme. We&#8217;ll do this soon. Anyway, click on &#8220;activate&#8221; to&#8230;. uh&#8230;.. activate the theme. Since MyTheme is a child of Classic, this means that MyTheme inherits all the characteristics of Classic. We can add to or modify these characteristics, but we haven&#8217;t done that yet, so right now our theme should look identical to Classic. Visit your site&#8217;s homepage to check on this&#8230;&#8230;</p>
<p>Whoops!</p>
<p>Our page looks like it has no styles! I guess I lied. MyTheme inherits everything from Classic <strong><em>except</em></strong> the style sheet. That&#8217;s a little odd right? Especially if you&#8217;re used to dealing with inheritance in things like children and object oriented programming, but no matter, it&#8217;s easier to fix than your&#8230;. well, than, many things. So, let&#8217;s grab the style sheet from the classic theme using the line:</p>
<ol>
<li>
<pre>@import url("../classic/style.css");</pre>
</li>
</ol>
<p>So now our entire wp-content/themes/mytheme/style.css file looks like:</p>
<ol>
<li>
<pre>/*</pre>
</li>
<li>
<pre>Theme Name:     My Theme</pre>
</li>
<li>
<pre>Theme URI:      http: //netlumination.com/</pre>
</li>
<li>
<pre>Description:    Child theme spawned by the Classic theme</pre>
</li>
<li>
<pre>Author:         Peter Ajtai</pre>
</li>
<li>
<pre>Author URI:     http: //peter-ajtai.com/</pre>
</li>
<li>
<pre>Template:       classic</pre>
</li>
<li>
<pre>Version:        1.0</pre>
</li>
<li>
<pre>*/</pre>
</li>
<li>
<pre>@import url("../classic/style.css");</pre>
</li>
</ol>
<p>Ok, now go and check on how your home page looks&#8230;. Just like classic, huh? Well, that&#8217;s not very interesting, let&#8217;s make things a very tiny bit more interesting by adding one more line to prove that we have a theme that uses default but has some of it&#8217;s own rules:</p>
<ol>
<li>
<pre>/*</pre>
</li>
<li>
<pre>Theme Name:     My Theme</pre>
</li>
<li>
<pre>Theme URI:      http: //netlumination.com/</pre>
</li>
<li>
<pre>Description:    Child theme spawned by the Classic theme</pre>
</li>
<li>
<pre>Author:         Peter Ajtai</pre>
</li>
<li>
<pre>Author URI:     http: //peter-ajtai.com/</pre>
</li>
<li>
<pre>Template:       classic</pre>
</li>
<li>
<pre>Version:        1.0</pre>
</li>
<li>
<pre>*/</pre>
</li>
<li>
<pre>@import url("../classic/style.css");</pre>
</li>
<li>
<pre>body {</pre>
</li>
<li>
<pre>	background-color:blue;</pre>
</li>
<li>
<pre>}</pre>
</li>
</ol>
<p>Ok, that was 3 lines, but I could have made it one line. Does it work? Yup. Does it work with all themes&#8230;&#8230; uh, no. For example, if you try the same thing with the Default theme, you&#8217;ll notice that some of the background images that are used in the Default theme will not be used in your child theme. This is because the CSS for these background images are created by PHP that looks for them in the wrong directory. It&#8217;s easy to fix, but it illustrates why I&#8217;m using so many words to explain this one simple thing of how to make a child theme. If you know how all of this works, you can probably track down these problems. If you don&#8217;t know how it works, you&#8217;re lost. But these details aren&#8217;t important right now, since we want to create our own theme, not look for weird little leaks in the inheritance abstraction for WordPress themes.</p>
<p>You&#8217;ve just created your own WP theme! Don&#8217;t worry it gets better. We&#8217;ll do stuff that&#8217;s more useful. We&#8217;ll push pixels around around like they&#8217;re not our boss. We&#8217;ll meld code to our mind&#8217;s desire, but you&#8217;ll have to wait for the next part of this series for that&#8230; until then we&#8217;ll&#8230;.. well, we&#8217;ll see you later.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/creating-your-first-wordpress-theme-part-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Multiple Loops in WordPress with query_posts() and get_categories()</title>
		<link>http://netlumination.com/blog/using-multiple-loops-in-wordpress-with-query_posts-and-get_categories</link>
		<comments>http://netlumination.com/blog/using-multiple-loops-in-wordpress-with-query_posts-and-get_categories#comments</comments>
		<pubDate>Tue, 05 May 2009 20:12:53 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Category]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[get_categories]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[query_posts]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[The Loop]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=390</guid>
		<description><![CDATA[This is a tutorial to demonstrate how to show entire posts from multiple categories in WordPress. This would be especially useful for blogs that contain very short posts like a photo with a short description. This is a very simple problem and solution, but I didn&#8217;t find many posts describing how to do it, so [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tutorial to demonstrate how to show entire posts from multiple categories in WordPress. This would be especially useful for blogs that contain very short posts like a photo with a short description. This is a very simple problem and solution, but I didn&#8217;t find many posts describing how to do it, so I thought it may help a few people out.</p>
<p>In some blogs, it can be useful to show entire posts from multiple categories on one page. For instance for a recipe blog you may want to list the name of each of your recipe categories and the recipes in each of those categories. This would look something like:</p>
<ul>
<li>Breakfast Recipes
<ul>
<li>[Eggs Benedicts Recipe Post]</li>
<li>[Pancakes Recipe Post]</li>
</ul>
</li>
<li>Lunch Recipes
<ul>
<li>[Grilled Cheese Sandwish Recipe Post]</li>
</ul>
</li>
<li>Dinner Recipes
<ul>
<li>[Fettucini Alfredo Recipe Post]</li>
<li>[Lasagna Recipe Post]</li>
</ul>
</li>
</ul>
<p><span id="more-390"></span>WordPress uses <a href="http://codex.wordpress.org/The_Loop">The Loop</a> to display posts. In this case we want to first retrieve all the categories from the database, then we want to cycle through each category and use The Loop to display all the posts in that category.</p>
<p>For most pages on your WordPress site, the url of the page will contain a query string which will dictate which posts are shown with The Loop. We can overide any existing query string using the <a href="http://codex.wordpress.org/Template_Tags/query_posts">query_posts()</a> function to display the specific posts we want. The nice thing is that we can use the <a href="http://codex.wordpress.org/Template_Tags/query_posts">query_posts()</a> function multiple times in order to run The Loop multiple times on the same page.</p>
<p>There are several ways of using <a href="http://codex.wordpress.org/The_Loop#Multiple_Loops">multiple Loops</a> in WordPress. With using multiple query_posts, the only trick is that you should save and reset the original query for the page. This is so that later down the page (like in the Sidebar) you can use all the functions that apply to the page you&#8217;re on and not on the last query_post you performed. The query is stored in $wp_query, so we can use <code>&lt;?php $temp_query = $wp_query; ?&gt;</code> before the Loops to save the query, and we can use <code>&lt;?php $wp_query = $temp_query; ?&gt;</code> at the end of the Loops to retrieve it. This is like in Multiple Loops Example 2 from <a href="http://codex.wordpress.org/The_Loop#Multiple_Loops">The Loops WordPress page</a>.</p>
<p>There are basically two important parts of this loop. First we must create an array that lists all the categories. Then we cycle through that array and retrieve all the posts from each category, one category at a time. To create an array of all the categories we&#8217;ll use <a href="http://codex.wordpress.org/Function_Reference/get_categories">get_categories()</a>. This simply returns an array with all the categories. Now, this array has a lot of information associated with it. To get an idea of what it looks like you can always print the array out in readable form with <code>&lt;?php print_r( get_categories() ); ?&gt;</code> . There&#8217;s information like the name and category ID for each category. We&#8217;ll make use of those.</p>
<p><script type="text/javascript">// <![CDATA[
 google_ad_client = "pub-4166122661117213"; /* 336x280, created 4/27/09 */ google_ad_slot = "9673694336"; google_ad_width = 336; google_ad_height = 280;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<p>To show the posts in a category we have to use query_posts and an identifying characteristic of the category we want. The name of the category isn&#8217;t always the best solution. For example if you have a category called, &#8220;Breakfast &amp; Juices,&#8221; the ampersand will trip the PHP up, so we&#8217;ll just use the ID number of the category. If we make our category array like this: <code>&lt;?php $categories=get_categories(); ?&gt;</code> . Then we can retrieve the category ID from the created array with <code>category-&gt;cat_ID</code>. We can retrieve the name of the category with <code>$category-&gt;name</code>.</p>
<p>Finally, putting everything together we get:</p>
<ol>
<li>
<pre>&lt;?php $temp_query = $wp_query; ?&gt;</pre>
</li>
<li>
<pre>  &lt;?php $categories=get_categories();</pre>
</li>
<li>
<pre>  foreach($categories as $category)</pre>
</li>
<li>
<pre>  { ?&gt;</pre>
</li>
<li>
<pre>    &lt;h2&gt;&lt;?php echo($category-&gt;name); ?&gt;&lt;/h2&gt;</pre>
</li>
<li>
<pre>    &lt;?php query_posts("cat=$category-&gt;cat_ID"); ?&gt;</pre>
</li>
<li>
<pre>    &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;</pre>
</li>
<li>
<pre>      [ YOUR POST DISPLAYING CODE GOES HERE ]</pre>
</li>
<li>
<pre>    &lt;?php endwhile; endif; ?&gt;</pre>
</li>
<li>
<pre>  } ?&gt;</pre>
</li>
<li>
<pre>&lt;?php $wp_query = $temp_query; ?&gt;</pre>
</li>
</ol>
<p>If you want to see what happens if you don&#8217;t reassign the original query just remove the last line. It will probably make your sidebar say something odd&#8230; though the particulars will depend on the theme you&#8217;re using.</p>
<p>This solution will work if you do not have child categories. If you do have child categories (an example would be Ice Cream category in the Deserts parent category), then you will get repetition of posts, since this will display all the posts from all parent categories then the posts for child categories. There are several ways to resolve this. The simplest way is to only display parent categories and not child categories. To do this we must check if a category is a child before we display it&#8217;s posts. To do this we&#8217;ll use <code>$category-&gt;parent</code>. This returns the parent of the category. If it returns nothing, or false, we know that the category is not a child but a parent. We&#8217;ll put an if statement that only proceeds if there is no parent of the category inside the foreach loop. Here we go:</p>
<ol>
<li>
<pre>&lt;?php $temp_query = $wp_query; ?&gt;</pre>
</li>
<li>
<pre>&lt;?php $categories=get_categories();</pre>
</li>
<li>
<pre>foreach($categories as $category)</pre>
</li>
<li>
<pre>{</pre>
</li>
<li>
<pre>  if(!$category-&gt;parent)</pre>
</li>
<li>
<pre>  { ?&gt;</pre>
</li>
<li>
<pre>    &lt;h2&gt;&lt;?php echo($category-&gt;name); ?&gt;&lt;/h2&gt;</pre>
</li>
<li>
<pre>    &lt;?php query_posts("cat=$category-&gt;cat_ID"); ?&gt;</pre>
</li>
<li>
<pre>    &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;</pre>
</li>
<li>
<pre>      [ YOUR POST DISPLAYING CODE GOES HERE ]</pre>
</li>
<li>
<pre>    &lt;?php endwhile; endif; ?&gt;</pre>
</li>
<li>
<pre>  } ?&gt;</pre>
</li>
<li>
<pre>}</pre>
</li>
<li>
<pre>&lt;?php $wp_query = $temp_query; ?&gt;</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/using-multiple-loops-in-wordpress-with-query_posts-and-get_categories/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to SEO header meta keywords and descriptions with WordPress</title>
		<link>http://netlumination.com/blog/how-to-seo-header-meta-keywords-and-descriptions-with-wordpress</link>
		<comments>http://netlumination.com/blog/how-to-seo-header-meta-keywords-and-descriptions-with-wordpress#comments</comments>
		<pubDate>Fri, 24 Apr 2009 18:23:26 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[keywords]]></category>
		<category><![CDATA[search engine optimization]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=254</guid>
		<description><![CDATA[The default WordPress installation does not produce either a description or keywords meta tag in the header. There are plugins you can use to solve this problem, but why use a plugin when you can solve the problem with a few lines of code? Writing the code yourself with teach you about WordPress, PHP, and [...]]]></description>
			<content:encoded><![CDATA[<p>The default WordPress installation does not produce either a description or keywords meta tag in the header. There are plugins you can use to solve this problem, but why use a plugin when you can solve the problem with a few lines of code? Writing the code yourself with teach you about WordPress, PHP, and XHTML. This will enable you to solve  future web site problems easier. Additionally, you&#8217;ll have one less plugin to keep track of, giving you a leaner, meaner, WordPress installation.</p>
<p>After a brief introduction, I&#8217;ll delve right into the code, and show you how to add these meta tags to your pages by modifying the header.php file of your theme.<span id="more-254"></span></p>
<p>While the description and keyword meta tags are not as important for search engine optimization (SEO) as they used to be, they are still important. The description is often used verbatim as the wording under a link to your site by many search engines. Keywords may be less important, since search engine now often rely on the content of your pages, but it can be nice to include them for that extra little boost in SEO and as a reminder to yourself of what words you are  trying to optimize a particular page to.</p>
<p>This solution will write out custom keywords and description for all you WordPress pages and individual blog posts. We will make use of the &#8220;Custom Fields&#8221; area for your posts and pages in the WordPress administration panel. This will allow us to customize each post and page, and the meta information will be readilly visible in the administration panel when we look at a post or page.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4166122661117213";
/* 336x280, created 4/27/09 */
google_ad_slot = "9673694336";
google_ad_width = 336;
google_ad_height = 280;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> </p>
<p>The first step is to create two new custom fields, one for the keywords and one for the description. Open your Worpress administration panel and click to edit an existing post or page. Under the Custom Fields area choose &#8220;Enter New&#8221; and create a field for keywords and a field for the description:  </p>
<p><img class="aligncenter size-full wp-image-259" title="new-custom-field" src="http://netlumination.com/wp-content/uploads/2009/04/new-custom-field.jpg" alt="new-custom-field" width="400" height="229" /> </p>
<p>I called mine &#8220;seo-description&#8221; and &#8220;seo-keywords&#8221;:  </p>
<p><img class="aligncenter size-full wp-image-258" title="the-custom-fields" src="http://netlumination.com/wp-content/uploads/2009/04/the-custom-fields.jpg" alt="the-custom-fields" width="400" height="179" /></p>
<p>Now, you can go ahead and fill out the meta information for each post and page. I&#8217;d suggest only filling out the description and keywords for one post. You can use this one as a test post. Once you see that everything is working correctly, you can go back and fill out the information for all the other pages and posts.  Okay, now we&#8217;re going to start to add in the code that will make everything display correctly. We&#8217;re going to be working witht he &#8220;header.php&#8221; file of you current theme. So, go ahead and open up the file&#8230;. You can check what them you are using in your admin panel. Just click on Appearance &gt;&gt; Themes. Under &#8220;Current Theme&#8221; there&#8217;ll be a line that says, all of this theme&#8217;s files are located in, &#8220;themes/blah-blah.&#8221; Go to that directory and fetch header.php through FTP or just use the built in editor in the admin panel. This is found at Appearance&gt;&gt;Editor. Under &#8220;Theme Files&#8221; click on &#8220;Heder (header.php).&#8221;  We want our meta information to appear in the header, usually right below the title. The end result we are looking for is something like this:</p>
<blockquote><p>
<code>&lt;title&gt;Your Blogs Title&lt;/title&gt;</code><br />
<code> &lt;meta name="description" content="[your custom description for this page]" /&gt; </code> <code>&lt;meta name="keywords" content="[your custom keywords for this page]" /&gt;</code></p></blockquote>
<p>Let&#8217;s start with the description. First we&#8217;ll check whether the page or post has a custom description. If it does, we&#8217;ll display that. If it doesn&#8217;t we&#8217;ll just display your blogs tagline. The trick here is that in WordPress there is a <a href="http://codex.wordpress.org/Function_Reference/get_post_meta">get_post_meta function</a> that you can use to retrieve the custom keyword and description info you put in. If you on your site somewhere where you are showing only a single blog post or a single page this function will work.  Let&#8217;s try:</p>
<blockquote><p>
<code>&lt;?php $seodescription = get_post_meta($post-&gt;ID, "seo-description", true); ?&gt;</code></p></blockquote>
<p>This will get our meta description, &#8220;seo-description&#8221; for the post we are displaying and assign it to the variable $seodescription (it&#8217;s not good to use variables with hyphens in PHP ).  Now we can simply use </p>
<blockquote><p>
<code>&lt;?php echo $seodescription; ?&gt;</code></p></blockquote>
<p>This will print out the custom description. So far our solution is:</p>
<blockquote><p>
<code>&lt;meta name="description" content="&lt;?php $seodescription = get_post_meta($post-&gt;ID, "seo-description", true); echo $seodescription; ?&gt;" /&gt;</code></p></blockquote>
<p>This is one of the things that is so nice about PHP. You can insert it directly into XHTML wherever you want.  The only problem is that we may have a page or post that we haven&#8217;t gotten around to adding custom keyword and description meta tags to. The about code will not create an error in this case. It will just print empty quotation marks. This is because the PHP variable $seodescription will be zero if get_post_meta finds nothing. We can make use of this with an if statement. In php an if statement will execute if the condition is not zero, and the if statement will not execute if the condition is zero.  In other words</p>
<blockquote><p>
<code>if ( $mynumber = 0 ) { echo "hi!"; } else { echo "bye...";}</code></p></blockquote>
<p>Will print &#8220;bye&#8230;&#8221; because the if statement is 0. 0 means false to PHP. So, of course</p>
<blockquote><p>
<code>if ( $mynumber = 8.5 ) { echo "hi!"; } else { echo "bye...";}</code></p></blockquote>
<p>Will print &#8220;hi!&#8221; since the if statement is not 0.  Let&#8217;s apply this to meta tags. If there is custome meta description, we will display it, and if there is none, we will nothing. It&#8217;s not a good idea to put a default description or keywords on pages, since this will make multiple pages have the same description and keywords. This is confusing for search engines, since how can two pages have the same descriptin but different content? We will check if there is a custom description with an if statement. The only tricky part here is that PHP actually goes ahead and assigns a value to the variable inside the if statement. This is because we used &#8220;=&#8221; which means set equal to. So, here goes:</p>
<blockquote><p>
<code>&lt;?php if ($seodescription = get_post_meta($post-&gt;ID, "seo-description", true))</code> <code> <span> </span>{ ?&gt;  <span style="font-family: Georgia; ">&lt;meta name="description" content="&lt;?php echo $seodescription; ?&gt;" /&gt;&lt;?php</span> <span style="font-family: Georgia; "><span style="font-family: -webkit-monospace; ">} ?&gt;</span></span> </code>  </p></blockquote>
<p>Now we just do the same for the keywords. So for keywords, using the same idea as above we have:</p>
<blockquote><p>
<code>&lt;?php if ($seokeywords = get_post_meta($post-&gt;ID, "seo-keywords", true))</code> <code> <span> </span>{ ?&gt;  &lt;meta name="keywords" content="&lt;?php echo $seokeywords; ?&gt;" /&gt;&lt;?php  <span> </span>} ?&gt; </code></p></blockquote>
<p>There is one final thing to take care of. If we use this code as is, then on pages that dispaly multiple posts, we&#8217;re going to display the description and keywords for just the first post. To get around this we&#8217;ll use the WordPress function <a href="http://codex.wordpress.org/Function_Reference/is_singular">is_singular()</a> . This function returns true if only one page or post is being displayed and false if not. You can use an else statement to display defualt meta data. This default meta date will only go on pages that show more than one post.  Ok, so here we have the whole enchilada starting with the title tag:</p>
<blockquote><p>
<code>&lt;title&gt;CODE-TO-DISPLAY-MY-BLOG-NAME&lt;/title&gt;</code></p></blockquote>
<blockquote><p>
<code> &lt;?php  if ( is_singular() )   </code></p></blockquote>
<blockquote style="padding-left: 30px; "><p>
<code>{ </code></p></blockquote>
<blockquote style="padding-left: 30px;"><p>
<code> <code>if ($seodescription = get_post_meta($post-&gt;ID, "seo-description", true))</code> </code></p></blockquote>
<blockquote style="padding-left: 60px;"><p>
<code><code> { ?&gt; </code></code></p></blockquote>
<blockquote style="padding-left: 60px;"><p>
<code><code> &lt;meta name="description" content="&lt;?php echo $seodescription; ?&gt;" /&gt;&lt;?php </code></code></p></blockquote>
<blockquote style="padding-left: 60px;"><p>
<code><code> } ?&gt; </code> <code>&lt;?php </code></code></p></blockquote>
<blockquote style="padding-left: 30px;"><p>
<code><code>if ($seokeywords = get_post_meta($post-&gt;ID, "seo-keywords", true))</code> </code></p></blockquote>
<blockquote style="padding-left: 60px;"><p>
<code><code> { ?&gt; </code></code></p></blockquote>
<blockquote style="padding-left: 60px;"><p>
<code><code> &lt;meta name="keywords" content="&lt;?php echo $seokeywords; ?&gt;" /&gt;&lt;?php </code></code></p></blockquote>
<blockquote style="padding-left: 60px;"><p>
<code><code> }</code></code></p></blockquote>
<blockquote style="padding-left: 30px;"><p>
} ?&gt;</p></blockquote>
<p><script type="text/javascript"><!--
google_ad_client = "pub-4166122661117213";
/* 336x280, created 4/27/09 */
google_ad_slot = "9673694336";
google_ad_width = 336;
google_ad_height = 280;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<p>Take a look at this page. Here is what my admin panel looks like for this post:</p>
<p><img class="aligncenter size-full wp-image-265" title="this-post" src="http://netlumination.com/wp-content/uploads/2009/04/this-post.jpg" alt="this-post" width="450" height="125" /></p>
<p>And here you can see that the meta tags are really displayed in the source page (or you can check in your own browser):</p>
<p><img class="aligncenter size-full wp-image-266" title="source-code" src="http://netlumination.com/wp-content/uploads/2009/04/source-code.jpg" alt="source-code" width="450" height="128" /></p>
<p>And there we have it, custom keyword and description meta tags for your WordPress theme using no plugins.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/how-to-seo-header-meta-keywords-and-descriptions-with-wordpress/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
