<?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>Web Cash &#187; template</title>
	<atom:link href="http://www.earn-web-cash.com/tag/template/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Google Analytics: Inserting Into a WordPress Template</title>
		<link>http://www.earn-web-cash.com/2008/03/29/google-analytics-wordpress/</link>
		<comments>http://www.earn-web-cash.com/2008/03/29/google-analytics-wordpress/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 17:00:48 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Online Tools]]></category>
		<category><![CDATA[Redirected]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Analytics]]></category>
		<category><![CDATA[Stat Tracking]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/29/google-analytics-wordpress/</guid>
		<description><![CDATA[Google Analytics is a great tool for gathering data about your website. You can track and analyze all kinds of data about your visitors, their navigation paths, and the effectiveness of your content. To use Google Analytics, you need to place some javascript on your website. A commonly asked question in forums is, &#8220;How do [...]]]></description>
			<content:encoded><![CDATA[<p>Google Analytics is a great tool for gathering data about your website.  You can track and analyze all kinds of data about your visitors, their navigation paths, and the effectiveness of your content.</p>
<p>To use Google Analytics, you need to place some javascript on your website.  A commonly asked question in forums is, &#8220;How do I add Google Analytics to my WordPress template?&#8221;<br />
<span id="more-184"></span></p>
<h4>Where the Analytics Code Goes</h4>
<p>When you sign up for Google Analytics, Google provides you with a short piece of javascript to place on your site.  The code should look like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
var gaJsHost = ((&quot;https:&quot; == document.location.protocol) ? &quot;https://ssl.&quot; : &quot;http://www.&quot;);
document.write(unescape(&quot;%3Cscript src='&quot; + gaJsHost + &quot;google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E&quot;));
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
var pageTracker = _gat._getTracker(&quot;UA-2894597-3&quot;);
pageTracker._initData();
pageTracker._trackPageview();
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>According to Google&#8217;s instructions, this needs to be placed at the very end of your site &#8211; just before the closing body tag.  To do this, we need to find the closing body tag on the WordPress template.</p>
<h4>Look In Footer.php</h4>
<p>As we previously discovered, a <a href="http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/">WordPress template</a> is made up of a series of files.  Three basic files &#8211; header.php, sidebar.php, and footer.php &#8211; help build the components of the page.</p>
<p>If your WordPress template follows normal conventions, the closing body tag should be in the footer.php file.</p>
<p>Go to your themes directory of the WordPress installation, navigate to your current theme, and open footer.php.  You should see something like this at the end.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?php wp_footer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Add a blank line before the closing body tag.  Simply copy and paste the javascript code that Google provides on that blank line, save the file, and you&#8217;re good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/29/google-analytics-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anatomy of a WordPress Template: The Basics</title>
		<link>http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/</link>
		<comments>http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 23:46:12 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/</guid>
		<description><![CDATA[There are tons of free WordPress templates available, but at some point you&#8217;ll probably want to modify one or make your own. Even if you know HTML pretty well, this can be a daunting task at first. WordPress templates have a decent amount of simple PHP mixed in, and you need to utilize a special [...]]]></description>
			<content:encoded><![CDATA[<p>There are tons of free WordPress templates available, but at some point you&#8217;ll probably want to modify one or make your own.  Even if you know HTML pretty well, this can be a daunting task at first.</p>
<p>WordPress templates have a decent amount of simple PHP mixed in, and you need to utilize a special file structure for the template to operate correctly.  Before you dive into making a WordPress template, let&#8217;s look at the basic structure of a WordPress template compared to a normal website template.<br />
<span id="more-175"></span></p>
<h4>Example Basic Website Template</h4>
<p>A typical website consists of a few parts &#8211; the content, a header, and a footer.  You may also have a sidebar for navigation and/or a horizontal menu bar.  The typical markup for this type of template would look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;</span>
  ...  Header Stuff Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
  ...  Main Content Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidebar&quot;</span>&gt;</span>
  ...  This floats to a side ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;footer&quot;</span>&gt;</span>
  ...  Footer Stuff Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>If you&#8217;ve learned some PHP, then you can include a series of PHP files to create your webpage template.  Chances are your header, footer, and sidebar are the same for all or most of your pages &#8211; so it makes sense to create them one time each.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'header.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
  ...  Main Content Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sidebar.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'footer.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span></pre></div></div>

<p>Nothing too complicated here.  Just a simple, barebones template.</p>
<h4>What Does a WordPress Template File Look Like?</h4>
<p>Although the terminology is a bit different, a WordPress template has the same basic structure.  Let&#8217;s look at a pared down version of the default template&#8217;s index.php file.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?php get_header<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;narrowcolumn&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;?php if <span style="color: #66cc66;">&#40;</span>have_posts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : ?&gt;</span>
    <span style="color: #009900;">&lt;?php while <span style="color: #66cc66;">&#40;</span>have_posts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : the_post<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post-&lt;?php the_ID(); ?&gt;</span></span>&quot;&gt;
      ... Post Info ...
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;?php endwhile; ?&gt;</span>
  <span style="color: #009900;">&lt;?php endif; ?&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php get_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php get_footer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span></pre></div></div>

<p>The bulk of the action here is in the &#8220;content&#8221; div.  With PHP, WordPress checks to see if any posts were retrieved from the database.  If they are, then it loops through the posts and outputs each one.</p>
<p>&#8220;Post Info&#8221; would be replaced by the markup you want to use for the actual post headings, information, and content.</p>
<p>The PHP function calls are similar to the include() calls in the earlier template.  get_header() fetches the standard header info, get_sidebar() fetches the sidebar, and get_footer() fetches the footer.  But where does WordPress find this information?</p>
<h4>Special WordPress Template Files</h4>
<p>WordPress uses some standard tempalte files to make these functions work.</p>
<p>For example, get_header() looks for the header.php file.  It&#8217;s more or less a proxy call for include(&#8216;header.php&#8217;).  To make WordPress work properly, therefore, you should include all of your header information in header.php.</p>
<p>The same goes for get_footer() and footer.php as well as get_sidebar() and sidebar.php.</p>
<p>So, to begin designing a WordPress template or to convert a regular website template to a WordPress template, you need to worry about four basic files:</p>
<ul>
<li>header.php &#8211; the header div and information</li>
<li>footer.php &#8211; the footer div and information</li>
<li>sidebar.php &#8211; the sidebar div and information</li>
<li>index.php &#8211; calls get_header(), get_footer(), and get_sidebar(), and contains the content div</li>
</ul>
<p>There are some other special files as well, but this is enough to get started.  Once you understand the basic structure of the template, you can look into customizing the information that is displayed for each post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Time Delay Posts in WordPress</title>
		<link>http://www.earn-web-cash.com/2008/03/08/time-delay-posts-wordpress/</link>
		<comments>http://www.earn-web-cash.com/2008/03/08/time-delay-posts-wordpress/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 17:06:28 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/08/time-delay-posts-wordpress/</guid>
		<description><![CDATA[One reason I&#8217;ve heard people say that they prefer a full-blown CMS to WordPress is that WordPress doesn&#8217;t allow time delayed posting. I was about to figure out a way to mod WordPress to make this possible &#8211; until I realized that there is some decent built-in functionality for time delaying. You can easily delay [...]]]></description>
			<content:encoded><![CDATA[<p>One reason I&#8217;ve heard people say that they prefer a full-blown CMS to WordPress is that WordPress doesn&#8217;t allow time delayed posting.  I was about to figure out a way to mod WordPress to make this possible &#8211; until I realized that there is some decent built-in functionality for time delaying.</p>
<p>You can easily delay the release of your posts into the main indexes (front page, archives, &#8220;Recent Posts&#8221; list, etc).  With a little bit of code, you can also restrict people from viewing the page before its appointed &#8220;Published&#8221; date.<br />
<span id="more-173"></span></p>
<h4>Delaying Publication: Setting a Date</h4>
<p>If all you want to do is delay the date and time that an article is &#8220;released&#8221; on your page&#8217;s index, you don&#8217;t have to do a whole lot of work.</p>
<p>Every article you post is &#8220;stamped&#8221; with a time by WordPress.  When you hit the &#8220;Publish&#8221; button, it checks the current time on the server and attaches that to your post.</p>
<p>You may not have noticed, but there&#8217;s an option for you to edit this time while you are working on the article.  For example, you could set the date back a week and backdate one of your posts.  For our purposes, we&#8217;ll set the date <strong>ahead</strong> &#8211; and WordPress won&#8217;t display your post in any indexes until that date arrives.</p>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/03/edit-timestamp-ss.png' title='Screenshot of the Edit Timestamp Widget'><img class='alignright' src='http://www.earn-web-cash.com/wp-content/uploads/2008/03/edit-timestamp-ss.thumbnail.png' alt='Screenshot of the Edit Timestamp Widget' /></a>In the &#8220;Write&#8221; section of your Dashboard, you should have a column of widgets on the righthand side (Categories, Discussion, Post Slug, etc).  If you scroll down a bit, there should be one titled &#8220;Post Timestamp.&#8221;  If you don&#8217;t see anything, click the &#8220;+&#8221; button in the title.</p>
<p>To set a custom release date, select &#8220;Edit Timestamp.&#8221;  Then use the inputs to enter the date and time you want the article released.  Voila &#8211; you&#8217;re done.</p>
<h4>Restricting Access to the Page</h4>
<p>For most people, this is good enough.  Your readers aren&#8217;t going to be able to find the article without a link to it appearing on your front page or in your RSS feed.</p>
<p>However, if your readers <strong>do</strong> know the link to the page, somehow, they can still access it directly.  If you want to prevent that, you&#8217;ll need to add a few lines of code to your template files.</p>
<p>We&#8217;re going to edit the &#8220;single.php&#8221; template file &#8211; the file responsible for formatting and displaying a single post.  After the page retrieves the post, we&#8217;re going to perform a check to see if the published date of the article is in the future.</p>
<p>If it is, we&#8217;ll display an alternative message to tell the user the article isn&#8217;t published yet.  Otherwise, the article will be displayed as normal.</p>
<h4>Editing Single.php</h4>
<p>Your template file probably doesn&#8217;t look exactly like mine, but there should be some very basic similarities.</p>
<p>If you open single.php, the page is displayed within &#8220;the loop.&#8221;  It&#8217;s how every WordPress template works.  The loop always begins with a line similar to this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This checks to see if a page was found in the database.  If it was, it loads the page into memory and prepares to output it.  The loop will eventually end with a line like this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We&#8217;re going to create a new if statement and place it in between these two lines.  The new template will look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pubDate</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;h3&gt;Article Not Published Yet&lt;/h3&gt;
  &lt;p&gt;Sorry!  The article you request is not published 
    yet.  It should be available soon, so check back in a few days.&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  ...  Regular post processing goes here ...
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Creating the Conditional Statement</h4>
<p>The only thing we have to do now is create a functioning conditional statement that checks to see if the published date of the article is in the past or the future.</p>
<p>To do that, we&#8217;ll use a few functions &#8211; get_the_time (a WordPress function to get the post&#8217;s timestamp), strtotime (a PHP function to convert a date string to a timestamp), and time (a php function to get the current tie).</p>
<p>get_the_time doesn&#8217;t return the actual time stamp &#8211; it returns a formatted date string, like &#8220;March 9, 2008, 11:13:35.&#8221;  You can specify how it&#8217;s formatted, just like you would with PHP&#8217;s date function.</p>
<p>To get the timestamp, we&#8217;re going to format the time string in a special way so that strtotime() can convert it back to a full timestamp (preserving the exact time the article should be published).  Then we compare that timestamp to the system time and see if the date has passed or not.</p>
<p>Use this if statement in the code above, and you should be good to go.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span>get_the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'F j, Y, H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you time delay an article and someone tries to access the article directly, they will now see your alternate message.  You should of course personalize that to something appropriate for your site.</p>
<p>You can also apply the same concept to &#8220;Pages&#8221; in WordPress.  You&#8217;ll need to edit the page.php template file and insert the same snippet of code there.</p>
<p>What are you waiting for?  Go write some articles for the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/08/time-delay-posts-wordpress/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Add Custom Loops (Queries) to WordPress</title>
		<link>http://www.earn-web-cash.com/2008/03/02/wordpress-custom-loops-queries/</link>
		<comments>http://www.earn-web-cash.com/2008/03/02/wordpress-custom-loops-queries/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 21:38:06 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/02/wordpress-custom-loops-queries/</guid>
		<description><![CDATA[If you look at your WordPress template, the thing that drives your page is called &#8220;the loop.&#8221; That&#8217;s WordPress speak for looping through the result set (the posts) retrieved from the database. If you wanted to make custom queries, you could certainly do that by diving straight into the database. However, WordPress comes with some [...]]]></description>
			<content:encoded><![CDATA[<p>If you look at your WordPress template, the thing that drives your page is called &#8220;the loop.&#8221;  That&#8217;s WordPress speak for looping through the result set (the posts) retrieved from the database.</p>
<p>If you wanted to make custom queries, you could certainly do that by diving straight into the database.  However, WordPress comes with some built in functions for helping you query the database and display the results.  By using these template tags, you can add custom loops in your template to display other post information.<br />
<span id="more-167"></span></p>
<h4>Looking At the Main Loop</h4>
<p>If you look in any of your templates, you&#8217;ll see a loop similar to the one below.  This basic loop just loops through all the articles, outputs the title and content.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h2&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
&lt;div&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>WordPress has a nasty habit of using that weird while/if syntax, where things aren&#8217;t enclosed in brackets.  Aside from the weird sytnax, this is a very simple while loop.</p>
<p>First, if (have_posts()) checks to see if there is any data in the queue to be outputted.  If there is, it starts a while loop that uses the same check &#8211; have_posts() &#8211; to see if it should continue.</p>
<p>The thing that moves this along is the_post().  This loads the next post in the result set into memory and prepares it for outputting.</p>
<p>The next few lines do our basic output.  the_title() is the template tag for outputting the title of the current article, while the_content() outputs the text of the article.</p>
<p>Finally, we wrap up the while loop and the if statement.  If there were more articles in the queue (like on an index/archive page), it would loop through for each article.</p>
<h4>Where Do the Articles Come From?</h4>
<p>When you load a page in WordPress, you use a query string.  The most basic one would be <code>index.php?p=5</code>.  That tells WordPress to load the article where the post id is 5.</p>
<p>You may not realize it if you&#8217;re using pretty URLs, but every URL you request on your blog has one of these query strings built-in.  It tells WordPress to load a list of articles (for an archive, category, or index) or to simply load one article or page.</p>
<p>There&#8217;s nothing stopping you from utilizing this process for other purposes, though.  Rather than simply looping through the result-set created by the query string, you can use the query_posts() function to create your own custom queries &#8211; and then loop through them.</p>
<h4>Example Please&#8230;?</h4>
<p>Here&#8217;s how it works.  You call query_posts() with a query string.  That loads the database results and prepares for the loop.  Then, you loop through like we did above to output information on the articles.</p>
<p>Let&#8217;s say you want to fetch the latest article that was tagged with both &#8220;foo&#8221; and &#8220;bar.&#8221;  Here&#8217;s how you do it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tag=foo+bar&amp;showposts=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//  Create the loop here</span></pre></div></div>

<p>We passed two parameters here.  &#8220;tag=foo+bar&#8221; tells WordPress to fetch articles that have both of those tags.  &#8220;showposts=1&#8243; tells WordPress to only fetch one article.  By default, they&#8217;re sorted by date and time, so we automatically fetch the latest one.</p>
<h4>You Don&#8217;t Always Need Plug-ins</h4>
<p>This is such a great tool because it lets you avoid using some basic plug-ins.  Plug-ins essentially help you perform these extra queries &#8211; like the latest posts, similar posts, etc.  But they can also be restricting if they don&#8217;t do exactly what you want.</p>
<p>By using query_posts() to fetch your own information, you can get WordPress to do exactly what you want.</p>
<p>For example, let&#8217;s say you write movie reviews and you want to display the latest ones in your sidebar.  Rather than look for a plug-in that displays exactly what you want it to, you can tag all of your movie reviews with &#8220;Movie Review&#8221; and query for those specific posts. </p>
<p>Then you can easily create the output you want, rather than the output someone else designed.</p>
<p>This is just a taste of what you can do with query_posts() and custom loops in WordPress.  You&#8217;ll need to try it out for yourself to fully understand it, and I&#8217;d suggest you take a look at the <a href="http://codex.wordpress.org/Template_Tags/query_posts">documentation on query_posts()</a> for a list of parameters and the <a href="http://codex.wordpress.org/Template_Tags/">documentation on template tags</a> for a full list of output tags.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/02/wordpress-custom-loops-queries/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Alternate CSS Styles Using PHP</title>
		<link>http://www.earn-web-cash.com/2008/02/13/alternate-css-styles-php/</link>
		<comments>http://www.earn-web-cash.com/2008/02/13/alternate-css-styles-php/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 04:08:08 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/13/how-to-alternate-css-styles-using-php/</guid>
		<description><![CDATA[There are a lot of situations in which you'd like to alternate CSS styles from one element to the next.  Long tables, for example, look a lot nicer when the background color of the rows is alternated (think: Gmail).

How do we do that?  Some pretty simple PHP can help you accomplish this task and spice up your HTML/CSS.]]></description>
			<content:encoded><![CDATA[<p>There are a lot of situations in which you&#8217;d like to alternate CSS styles from one element to the next.  Long tables, for example, look a lot nicer when the background color of the rows is alternated.</p>
<p>How do we do that?  Some pretty simple PHP can help you accomplish this task and spice up your HTML/CSS.<br />
<span id="more-111"></span></p>
<h5>Look At the HTML/CSS</h5>
<p>Before we start making things dynamic, let&#8217;s look at the basic HTML.</p>
<p>Let&#8217;s say we want to make a list of items &#8211; in a table &#8211; maybe a list of emails.  The end result should be a table with alternating background colors for rows &#8211; white and light blue.</p>
<p>If we were to create this table by hand, it might look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;blue&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>E-mail subject<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Sender<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;white&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>E-mail subject<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Sender<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></div></div>

<p>This assumes that we have a CSS class defined as &#8220;blue&#8221; with a blue background and &#8220;white&#8221; with a white background.</p>
<h5>Adding Some PHP to Assign Classes</h5>
<p>We&#8217;re setting the background color by adding a class declaration to the table row.  The first step in making this dynamic is to use PHP to echo the class.  Like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php echo 'blue'; ?&gt;</span></span>&quot;&gt;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span> ... <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></pre></div></div>

<p>We&#8217;ve taken the same table row element from before and replaced &#8220;blue&#8221; with a php snippet that echos the same phrase, &#8220;blue.&#8221;  The end result is the same HTML that we created in the first example.</p>
<h5>Dynamically Choosing the Class</h5>
<p>The final step in making this dynamic is to add a conditional statement to the PHP block.  For example, let&#8217;s say we&#8217;re executing a loop 5 times.  On the odd iterations (1, 3, 5) we&#8217;ll use &#8220;blue&#8221; as the class.  On the even iterations (2, 4), we&#8217;ll use &#8220;white.&#8221;</p>
<p>To test whether or not a number is odd, you can use the modulus (%) operator.  This returns the remainder of a division &#8211; so <code>2 % 3 = 1</code>.  With a little basic math theory, we know that if a number is divided by 2 and has no remainder it&#8217;s even &#8211; but if there&#8217;s a remainder of 1 it&#8217;s odd.</p>
<p>Here&#8217;s what the loop might look like.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;tr class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;blue&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;white&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;td&gt; ... &lt;/td&gt;&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h5>That If Statement Is Kind of Long&#8230;</h5>
<p>Well, we can shorten that up.  This is a great place to use the obscure and un-readable ternary operator in PHP.  It&#8217;s a shortcut that allows you to write a simple if-statement in one line.</p>
<p>For example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span> ? <span style="color: #0000ff;">&quot;Yes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;No&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The ternary operator takes three parts &#8211; the conditional statement (in this case I just wrote true), a value to return if the statement is true (&#8220;Yes&#8221;), and a value to return if the statement is false (&#8220;No&#8221;).  I echo&#8217;ed the result just so you could see what the statement outputs (in this case, &#8220;Yes&#8221;).</p>
<p>We turn our previous if statement into a ternary operator statement and shorten up that code block quite a bit.  Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;tr class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">&quot;blue&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;white&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;td&gt; ... &lt;/td&gt;&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Creating these table rows is just one example of how you can use PHP to help spice up your HTML.  With this concept, you can dynamically alternate styles based on a bunch of factors.</p>
<p>How else could you use this?</p>
<p>You could alternate the background colors of comments in your blog template.  You could include a bottom-border after every five rows in your table.  You could make a calendar module and display Saturday and Sunday in boldface.</p>
<p>The options are really endless &#8211; so long as you understand the basic principal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/13/alternate-css-styles-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

