<?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>jaredeasterday.com &#187; Blog</title>
	<atom:link href="http://www.jaredeasterday.com/category/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jaredeasterday.com</link>
	<description>...the home of another wordpress enthusiast</description>
	<lastBuildDate>Sat, 10 Sep 2011 19:36:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Word Camp SF 2011 Takeaways</title>
		<link>http://www.jaredeasterday.com/541/word-camp-sf-2011-takeaways/</link>
		<comments>http://www.jaredeasterday.com/541/word-camp-sf-2011-takeaways/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 02:26:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.jaredeasterday.com/?p=541</guid>
		<description><![CDATA[This year I finally got to attend my first Word Camp, and right here in my backyard: San Francisco!  It was great to get out and mingle with so many people that are as enthusiastic about this CMS as I am.  I think one of the most interesting questions I heard asked today was one [...]]]></description>
			<content:encoded><![CDATA[<p>This year I finally got to attend my first Word Camp, and right here in my backyard: San Francisco!  It was great to get out and mingle with so many people that are as enthusiastic about this CMS as I am.  I think one of the most interesting questions I heard asked today was one asked to the Core Developer team, that went something like this: &#8220;Why is it that you&#8217;re so committed to developing for WordPress, and not one of the other various platforms out there?&#8221;  <span id="more-541"></span></p>
<p>There were a few answers from the panel, but the common theme was that it was the community that really spoke to them.  True enough; I&#8217;ve always found the community to be fantastic, so it was awesome to see and interact in meat space for once.</p>
<p>Here are some personal takeaways from <a title="WordCamp SF 2011" href="http://2011.sf.wordcamp.org/program/saturday-mission-bay/">today&#8217;s WordCamp</a>, that I hope to expand on later:</p>
<ol>
<li>Learned about Post Formats with <a title="get_post_format()" href="http://codex.wordpress.org/Function_Reference/get_post_format">get_post_format()</a>, and heard some interesting things you can do with <a title="get_template_part()" href="http://codex.wordpress.org/Function_Reference/get_template_part">get_template_part()</a>.</li>
<li>Realized I should be marking up content in better ways, such as with &lt;article&gt; and &lt;figure&gt; tags.</li>
<li>Was kind of blown away when Ian Stewart said that <a title="the_content()" href="http://codex.wordpress.org/Function_Reference/the_content">the_content()</a> is King.  If you stuff a lot of data into custom meta boxes and custom fields and your user then switches to another theme that doesn&#8217;t support those features, the content will appear &#8220;gone&#8221; to them.</li>
<li>Before implementing a custom post type, first think about using a post format.</li>
<li>Learned that I should read the <a title="WordPress Philosophy" href="http://wordpress.org/about/philosophy/">WordPress Philosophy page</a>, and understand the heuristics that Daryl Koopersmith spoke about in his talk: Decisions, Not Options.</li>
<li>Picked up a thing or two about securing widgets: iframes, <a title="Needham–Schroeder protocol" href="http://en.wikipedia.org/wiki/Needham%E2%80%93Schroeder_protocol">Needham–Schroeder protocol</a>, and <a title="xPostMessage" href="https://github.com/mdawaffe/xPostMessage">xPostMessage</a> for secure frame communication.</li>
<li>Received some advice about releasing themes into the wild, and that the <a title="WordPress Theme Review" href="http://codex.wordpress.org/Theme_Review">WordPress Theme Review page</a> and <a href="http://codex.wordpress.org/WordPress_Coding_Standards">Coding Standards page</a> are good references.</li>
<li>Realized that I should be more involved in the <a title="WordPress Forum" href="http://wordpress.org/support/">WordPress forum</a>, and should make it a goal to <a title="Contributing to WordPress" href="http://codex.wordpress.org/Contributing_to_WordPress">contribute to WordPress</a></li>
<li>Found a few new blogs I should be following: <a title="http://wpcandy.com/" href="http://wpcandy.com/">wpcandy.com</a> and <a title="ma.tt" href="http://ma.tt/">ma.tt</a></li>
<li>Learned that I should be attending the weekly IRC Dev meetups, should be paying attention to the WordPress Dev blog: <a title="WordPress Development Blog" href="http://wpdevel.wordpress.com/">wpdevel.wordpress.com</a> and should be following WordPress bugs at <a href="http://core.trac.wordpress.org/">core.trac.wordpress.org</a></li>
<li>Remembered that I should learn more about media queries and <a title="Responsive Web Design" href="http://www.alistapart.com/articles/responsive-web-design/">responsive web design</a>.</li>
<li>Confirmed that Chris Coyier of <a href="http://css-tricks.com/">CSS-tricks</a> is amazing, hilarious, now lives in the bay area, and that I want to be his friend.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.jaredeasterday.com/541/word-camp-sf-2011-takeaways/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create, Read, and Update a Cookie using JavaScript</title>
		<link>http://www.jaredeasterday.com/530/how-to-create-read-and-update-a-cookie-using-javascript/</link>
		<comments>http://www.jaredeasterday.com/530/how-to-create-read-and-update-a-cookie-using-javascript/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 00:41:27 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.jaredeasterday.com/?p=530</guid>
		<description><![CDATA[While working on the redesign of the New York Law Journal, I was tasked with creating a pop-up message that was supposed to appear based on some logic that the business folks had.  Basically, the message was supposed to appear once per week, but no more than a total of 8 times, and then should [...]]]></description>
			<content:encoded><![CDATA[<p>While working on the redesign of the New York Law Journal, I was tasked with creating a pop-up message that was supposed to appear based on some logic that the business folks had.  Basically, the message was supposed to appear once per week, but no more than a total of 8 times, and then should never appear again.  In order to make this happen, I employed a few http cookies by way of JavaScript.<span id="more-530"></span></p>
<p>The way I ended up thinking about this was:</p>
<ol>
<li>The website visitor comes to our site, has no domain cookies, and should see the message once, but not again for another 7 days.  Our code at this point should:</li>
<ol>
<li>Show the message once</li>
<li>Set a cookie that will be responsible for showing the message once each week by expiring every 7 days. (7-day cookie)</li>
<li>Set a cookie that will be responsible for not showing the message after seeing it 8 times. (CookieCounter)</li>
</ol>
<li>Once the visitor returns to out site after 7 days, the first cookie we set should expire, and based on that we&#8217;ll:</li>
<ol>
<li>Show the message again</li>
<li>Set the 7-day cookie again</li>
<li>Update a value in the CookieCounter</li>
</ol>
<li>Once the visitor has seen the message 8 times, we won&#8217;t show it anymore, and we&#8217;ll determine this by looking at the CookieCounter value, which should have been updated each time the visitor saw that message.</li>
</ol>
<p>Using this logic, I went about coding this by first creating the 7-day Cookie, which is a self-invoking function:</p>
<pre>    (function setMyCookie(){
        var cookie = "my7DayCookie";
        var my7DayValue = 1;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 7);
        var tmp=cookie + "=" + my7DayCookie+ "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp;
    })();</pre>
<p>Now we want to create a very similar function to create the second CookieCounter cookie:</p>
<pre>    (function setMyCounterCookie(){
        var cookie = "counterCookie";
        myCounterCookieValue = 1;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 99999);
        var tmp2=cookie + "=" + myCounterCookieValue + "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp2;
    })();</pre>
<p>The last function we need to create is one that will find the value of a cookie:</p>
<pre>function getCookie(cookieValue) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i=0; i&lt;ARRcookies.length; i++) {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x === cookieValue) {
            return unescape(y);
        }    
    }
}</pre>
<p>And then we assign that value to a variable by running the function and giving it the cookie we&#8217;re trying to read as a parameter:</p>
<pre>var myCounterCookieValue = getCookie("counterCookie");</pre>
<p>Now that we&#8217;ve got our two functions that will create and read our cookies for us, we need to start building out our logic and creating these cookies when appropriate.  I started this by thinking about the first state that a user would be in:  they have no cookies set and have not been to the site.  I started by writing some code that went something like this:</p>
<pre>Pseudo code: if the user has no cookies, show the message...</pre>
<p>I found however that the code for determining if there was NOT a cookie started to get messy and I began running into errors.  Instead, I flipped it upside down and started writing something like this instead:</p>
<pre>Pseudo code: if the user has both cookies, do nothing, else do something...</pre>
<p>Here&#8217;s the basic structure of what I ended up with:</p>
<pre>if (document.cookie.indexOf("my7DayCookie") &gt;= 0 &amp;&amp; document.cookie.indexOf("counterCookie") &gt;= 0){
    // Look for our cookies and if found do nothing
} else if (document.cookie.indexOf("60DayCookie") &gt;= 0 &amp;&amp; myCounterCookieValue &lt; 8){
    // if the Cookie Counter is there and it's value is less than 8, fire the message
} else if (my60DayValue &gt;= 8 ) {
    // if the Cookie Counter value is greater than 8, do nothing
} else {
    // if none of the above resolve to TRUE, then we know it's a first time visitor, so fire the message, and set both cookies.
}</pre>
<p>So, now we have a logic structure and we have our functions for creating cookies, but one final thing we need to think about is how to update the counterCookie.  It starts with a value of 1, but needs to update each time the my7DayCookie is reset.  We do this by inserting a modified version of our counterCookie creator function in the first &#8220;else if&#8221; block where we know the counterCookie exists, but the my7DayCookie does not, meaning that the user has seen the message once and the my7DayCookie has expired:</p>
<pre>    (function setMyCounterCookie(){
        var cookie = "counterCookie";
        myCounterCookieValue++;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 99999);
        var tmp2=cookie + "=" + myCounterCookieValue + "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp2;
    })();</pre>
<p>In the above code, notice the only difference:</p>
<pre>myCounterCookieValue++;</pre>
<p>When this function runs, it will take the existing value the counterCookie holds and add 1 to it.  When we put it all together, it would look something like this:</p>
<pre>function getCookie(cookieValue) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i=0; i&lt;ARRcookies.length; i++) {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x === cookieValue) {
            return unescape(y);
        }    
    }
}

var myCounterCookieValue = getCookie("counterCookie");

if (document.cookie.indexOf("counterCookie") &gt;= 0 &amp;&amp; document.cookie.indexOf("my7DayCookie") &gt;= 0){

    // BOTH COOKIES PRESENT, SO DO NOTHING

} else if (document.cookie.indexOf("counterCookie") &gt;= 0 &amp;&amp; myCounterCookieValue &lt; 8 ){

    // SHOW MESSAGE BY INCLUDING MESSAGE CODE HERE

    // RESET THE my7DayCookie
    (function setMy7DayCookie(){
        var cookie = "my7DayCookie";
        var my7DayCookieValue = 1;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 7);
        var tmp=cookie + "=" + my7DayCookieValue + "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp;
    })();

    // UPDATE counterCookie, INCREASE ITS VALUE BY 1
    (function setMyCounterCookie(){
        var cookie = "counterCookie";
        myCounterCookieValue++;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 99999);
        var tmp2=cookie + "=" + myCounterCookieValue + "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp2;
        return myCounterCookieValue;
    })();

    //console.log("counterCookie Value = " + myCounterCookieValue);

} else if (myCounterCookieValue &gt;= 8 ) {

    //DO NOTHING, THE USER HAS SEEN THE MESSAGE 8 TIMES

} else {

    // SHOW THE MESSAGE AND SET BOTH COOKIES FOR THE FIRST TIME

    (function setMyCookie(){
        var cookie = "my7DayCookie";
        var my7DayCookieValue = 1;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 7);
        var tmp=cookie + "=" + my7DayCookieValue + "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp;
    })();

    (function setMyCounterCookie(){
        var cookie = "counterCookie";
        myCounterCookieValue = 1;
        var showAgain = new Date();
        showAgain.setDate(showAgain.getDate() + 99999);
        var tmp2=cookie + "=" + myCounterCookieValue + "; expires=" + showAgain.toGMTString() + "; path=/";
        document.cookie=tmp2;
        return myCounterCookieValue;
    })();
}</pre>
<p>I hope this was helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jaredeasterday.com/530/how-to-create-read-and-update-a-cookie-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a custom single.php Template in WordPress</title>
		<link>http://www.jaredeasterday.com/497/how-to-create-a-custom-single-php-template/</link>
		<comments>http://www.jaredeasterday.com/497/how-to-create-a-custom-single-php-template/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 18:58:34 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.jaredeasterday.com/?p=497</guid>
		<description><![CDATA[Have you ever needed or wanted to create a custom single.php template that would only be used by posts of a certain type?  When I was building the FARMcurious site I needed a way to display blog posts and product posts in different ways.  The products single template needed to show price, product info, photos, [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed or wanted to create a custom single.php template that would only be used by posts of a certain type?  When I was building the FARMcurious site I needed a way to display blog posts and product posts in different ways.  The products single template needed to show price, product info, photos, and be laid out differently than blog post single template.<span id="more-497"></span></p>
<p>After looking around the WordPress community for a bit I found numerous plugins that seemed like they would do the trick, but I really hate throwing plugins at a problem unless there&#8217;s a very compelling reason to do so.  After awhile though, I found a <a href="http://elliotjaystocks.com/blog/tutorial-multiple-singlephp-templates-in-wordpress/" target="_blank">post on elliotjaystocks.com</a> that immediately made sense, and the solution is dead simple.</p>
<p>Simply put: you just need your single.php file to make a few decisions for you.  A simple if statement will help determine which category the post is in, and once you know that you can build the single.php template by including other (custom) templates.</p>
<p>The first thing you want to do is copy the code in your single.php file and save it as two new files that we&#8217;ll call using single.php.  I named mine &#8220;default-single.php&#8221; and &#8220;product-single.php&#8221;.</p>
<p>Now, in our original single.php file, delete all of the code and replace it with something like below:</p>
<pre>&lt;?php
/*
Template: single.php
*/
get_header();
?&gt;

&lt;?php
   if ( in_category( array( '6', '11' ) )) {
      include(TEMPLATEPATH.'/default-single.php');
   }
   else {
      include(TEMPLATEPATH.'/product-single.php');
   }
?&gt;</pre>
<p>The first php block simply names the template and of course the get_header(); function grabs the header.php file.</p>
<p>The next php block starts an if statement, and in this example we&#8217;re looking for posts that are in a certain array of category IDs: 6 and 11.  If there are any posts in those categories, we&#8217;re going include the code from the default-single.php file.  Otherwise, the else statement will include the code from the product-single.php file.</p>
<p>In this manner you can customize your two new single.php templates any way you like, and utilize them by simply categorizing your posts appropriately.</p>
<p>I hope this comes in handy! Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jaredeasterday.com/497/how-to-create-a-custom-single-php-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with git</title>
		<link>http://www.jaredeasterday.com/477/getting-started-with-git/</link>
		<comments>http://www.jaredeasterday.com/477/getting-started-with-git/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 00:58:08 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.jaredeasterday.com/?p=477</guid>
		<description><![CDATA[Up until a few months ago, I never really needed to bother myself with a Version Control System (VCS).  For freelance work, things were simple enough to the point where I&#8217;d 1) Develop a website locally and then 2) Upload code to the server, and that was pretty much the end of it.  At the [...]]]></description>
			<content:encoded><![CDATA[<p>Up until a few months ago, I never really needed to bother myself with a Version Control System (VCS).  For freelance work, things were simple enough to the point where I&#8217;d 1) Develop a website locally and then 2) Upload code to the server, and that was pretty much the end of it.  At the office our CMS took care of most things, and for things it didn&#8217;t cover, we&#8217;d adopted a system of making a backup of the last file and going from there.<span id="more-477"></span></p>
<p>A few things happened that changed my take on the necessities of version control.</p>
<ol>
<li>At work we upgraded our CMS, which didn&#8217;t preserve our versions when it launched, and it was hard to track exactly <em>what</em> changed when we&#8217;d make backups.</li>
<li>Freelance clients started asking for updates and changes to their sites, and I didn&#8217;t want a bunch of backup files cluttering my directories.  I also want to be able to start tracking what changes were made, rather than tracking simply that changes had been made.</li>
</ol>
<p>So in the office we starting using <a href="http://savannah.nongnu.org/projects/cvs">CVS</a>, and at home I decided to try <a href="http://git-scm.com/">Git</a>.  Because Git seems to have a steeper leaning curve for those not used to working with a command line, I want to document what I&#8217;ve learned with it.  So if you&#8217;re in need of a VCS and you&#8217;re interested in Git, perhaps this will help.  At the very least, it&#8217;ll serve as a reminder to me!  Note: you may want to familiarize yourself with some of the basics of working with the command line or terminal before proceeding.</p>
<h2>Getting Started</h2>
<p>I used <a href="http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/">this great post over at Net.Tutsplus.com</a> as a guide, and it helped me tremendously.  After installing and configuring git, here&#8217;s how you set up one of your existing directories as a Git repository.</p>
<p>In my case, I have a version of WordPress installed locally that I use for development.  I want to have each theme have it&#8217;s own repository.</p>
<p>The first thing you need to do is navigate to the directory that you want to set up as a repository.  For me, that would be the theme&#8217;s directory in my local instal.</p>
<pre>cd /wordpress/wp-content/themes/myTheme</pre>
<p>Now that we&#8217;re in the directory that we want to track versions in, we need to initialize Git by typing:</p>
<pre>git init</pre>
<p>Once completed, you should see the following:</p>
<pre>Initialized empty Git repository in /wordpress/wp-content/themes/myTheme/.git/</pre>
<p>Okay, so now that we have the repository created, we need to actually commit some code to it. Do that by typing the following:</p>
<pre>git add .</pre>
<p>This will add all the files in your directory to the Git staging area. The &#8220;.&#8221; in the command means &#8220;get everything,&#8221; but you can specify what you want to add to the staging area by typing out the name of the file you&#8217;re interested in like so:</p>
<pre>git add header.php</pre>
<p>Now that we have all of our files in the staging area, we want to commit them to the repository. Remember that in this example we already have an entire code base that we want to add to the repository and that we want to modify later. Since this is our initial commit, we&#8217;ll want to indicate that in our comments. To commit with a comment on all files, type the following:</p>
<pre>git commit -m "initial commit"</pre>
<p>You should then see something like:</p>
<pre>[master (root-commit) 466ce7c] initial commit 56 files changed, 5602 insertions(+), 0 deletions(-)</pre>
<p>Which is followed by a list of all the files that were committed. At any time if you wonder what the status is of files in your repository, you can ask for the status:</p>
<pre>git status</pre>
<pre># On branch master
nothing to commit (working directory clean)</pre>
<p>Now that you have a committed repository, you can begin working on your code. Once you modify a file and save it, run the status command once again and you should see something like this:</p>
<pre># On branch master
# Changed but not updated:
# (use "git add  ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
#
# modified: top.php
#</pre>
<p>This means that Git is aware that you&#8217;ve changed something in your file. At whatever point you&#8217;re happy with the changes you&#8217;ve made to your code, you&#8217;ll need to add it to the staging area, and then commit it as illustrated above. There&#8217;s a simple way to do both of those things at once with this command:</p>
<pre>git commit -am 'your message here'</pre>
<p>The &#8220;-am&#8221; means that you&#8217;re both adding it and want to type out a message. This way you don&#8217;t have to run two separate commands to commit a change.<br />
Well, we&#8217;ve now used most of the git commands that I&#8217;m so far familiar with. Obviously there are many more things you can do with Git, but at this point we&#8217;ve got our directory, we&#8217;ve added and then committed code, and we&#8217;re on our way to tracking our code versions!</p>
<p>As I become more familiar with Git, I&#8217;m sure I&#8217;ll write some more about it. Hope you enjoy Git!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jaredeasterday.com/477/getting-started-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create a Flexible Page Template Using Custom Fields</title>
		<link>http://www.jaredeasterday.com/446/how-to-create-a-flexible-page-template-using-custom-fields/</link>
		<comments>http://www.jaredeasterday.com/446/how-to-create-a-flexible-page-template-using-custom-fields/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 22:33:27 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.jaredeasterday.com/?p=446</guid>
		<description><![CDATA[While working with my friends over at Gastronaut, they asked me if I could develop a way for them to create blog pages for each of their clients on the fly.  For instance, if they acquired ACME Corp as a client, they wanted to be able to create  a new page for ACME corp that [...]]]></description>
			<content:encoded><![CDATA[<p>While working with my friends over at <a href="http://www.gastronautsf.com">Gastronaut</a>, they asked me if I could develop a way for them to create blog pages for each of their clients on the fly.  For instance, if they acquired ACME Corp as a client, they wanted to be able to create  a new page for ACME corp that would then have a list of blog posts that were only for ACME.<span id="more-446"></span></p>
<p>Typically I&#8217;d create a custom page template for the client, and then use the query posts function to find only posts categorized as &#8220;ACME.&#8221;  However, since their clientele are growing, I didn&#8217;t want to have to create a new page template each time they acquired new business. Besides, that&#8217;s just too many page templates!  I searched around for what other wordpress developers might have done and surprisingly I didn&#8217;t find much.</p>
<p>So, here&#8217;s what I did:</p>
<p>I made a new page template and at the top I created a variable called $clientCategory and set its value to the &#8220;client&#8221; custom field value for the page in question. In our example, the client would create a page and using a custom field on the page, they&#8217;d type in &#8220;ACME.&#8221;</p>
<pre>&lt;?php $clientCategory = get_post_meta($post-&gt;ID, 'client', true); ?&gt;</pre>
<p>So at this point in our example, the $clientCategory variable value is  &#8221;ACME.&#8221;</p>
<p>Next, I use the global $query_string variable in order to find posts that aren&#8217;t just the contents of the page in WordPress.  And then I use the query_posts function to find all posts that have a category name equal to the value set in the page&#8217;s &#8220;client&#8221; custom field.  To do this, I concatenate the $clientCategory variable that we set above to the end of the category_name argument as so:</p>
<pre>&lt;?php
   global $query_string;
   query_posts('category_name=' . $clientCategory);
?&gt;</pre>
<p>So now if the client wants to create posts for ACME and have them show up on ACME&#8217;s page, all they have to do is categorize each post as ACME.  Now of course, this means that the Category Name and the &#8220;Client&#8221; custom field value on the Page have to be exactly the same in order for this to work, but it means that the client can create these pages on the fly and I don&#8217;t need to create new page templates.</p>
<p>For example, if they want to create a page of posts for a new client &#8220;Widgets Inc.&#8221; they simply need to create a new post category &#8220;Widgets&#8221; and then create a new page that uses the new page template, and enter in &#8220;Widgets&#8221; as the &#8220;client&#8221; custom field value for the new page.</p>
<p>I hope this makes sense, and I hope it helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jaredeasterday.com/446/how-to-create-a-flexible-page-template-using-custom-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

