<?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>Digging into WordPress &#187; echo</title>
	<atom:link href="http://digwp.com/tag/echo/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Multiple the_date() Functions Return Empty Date</title>
		<link>http://digwp.com/2009/10/the_date-returns-empty/</link>
		<comments>http://digwp.com/2009/10/the_date-returns-empty/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 15:45:58 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=829</guid>
		<description><![CDATA[Inside the loop, if you use the function the_date() to display the date the post was published, you may run into trouble. Specifically, if there are two posts published on the same day, the second one will return nothing for a date. To fix this, use the_time() instead. There is quirk though, as the_time() ouputs, [...]]]></description>
			<content:encoded><![CDATA[<p>Inside the loop, if you use the function the_date() to display the date the post was published, you may run into trouble. Specifically, if there are two posts published on the same day, the second one will return nothing for a date.</p>
<p>To fix this, use the_time() instead. There is quirk though, as the_time() ouputs, by default, literally a time like &#8220;6:02 pm&#8221;. You can pass date parameters into it though, and make it output a date instead like the_time(m/d/Y). This means that the date formatting is controlled by your theme though, instead of the Admin area. To get the control back, use this instead:</p>
<pre><code>the_time(get_option('date_format'));</code></pre>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/10/the_date-returns-empty/">Permalink</a> | <a href="http://digwp.com/2009/10/the_date-returns-empty/#comments">5 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/10/the_date-returns-empty/&title=Multiple the_date() Functions Return Empty Date">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/date/" rel="tag">date</a>, <a href="http://digwp.com/tag/echo/" rel="tag">echo</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/10/the_date-returns-empty/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Global Custom Fields</title>
		<link>http://digwp.com/2009/09/global-custom-fields/</link>
		<comments>http://digwp.com/2009/09/global-custom-fields/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 11:49:35 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[custom-fields]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=659</guid>
		<description><![CDATA[UPDATE: Make sure to take out &#8220;Take Two&#8221; on this concept, with a cleaner method for doing this. Custom fields allow us to attach data to Posts or Pages that we can yank out and use at will in our templates. They are awesomely flexible and single-handedly allow WordPress to be used for about any [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE</strong>: Make sure to take out &#8220;<a href="http://digwp.com/2009/09/global-custom-fields-take-two/">Take Two</a>&#8221; on this concept, with a cleaner method for doing this.</p>
<p>Custom fields allow us to attach data to Posts or Pages that we can yank out and use at will in our templates. They are awesomely flexible and single-handedly allow WordPress to be used for about any CMS need. The fact that they can only be used on single Posts can be limiting in some circumstances. Sometimes you wish you could grab a custom value that you can control and is consistent globally, regardless of the current post. In this post we&#8217;ll look at a technique to do so.</p>
<p><span id="more-659"></span></p>
<h3>Fair Warning</h3>
<p>This might not be the perfect technique. If you read this and have a smarter way, I&#8217;m all ears, this worked for me in my quick testing. What would really be slick is to make a plugin out of this, where you can create global key/value pairs through a special settings panel that could be use anywhere.</p>
<p>WordPress already has a somewhat-similar system in place through how the <a href="http://codex.wordpress.org/Template_Tags/bloginfo">bloginfo</a> function works. </p>
<pre><code>&lt;?php bloginfo('name'); ?&gt;</code></pre>
<p>Perhaps that could be tapped into and expanded upon, I dunno.</p>
<h3>Example Use</h3>
<p>One idea is for something like an Amazon affiliate ID code. You might use a value like this all over the place on a site, embedding within amazon links and widgets. If you hard-code this value, and then need to change it someday, that would suck. It would be better to save this value in one place, and use a variable (global custom field) to output it.</p>
<h3>1. Create a Page</h3>
<p>Call it &#8220;Global Custom Fields&#8221;. It doesn&#8217;t need any content, but you can use this page to add the custom fields you wish to use globally.</p>
<p><img src="http://digwp.com/wp-content/blog-images/globalcustomfieldspage.png" width="589" height="300" alt="" title="" /></p>
<p>Notice down below, we just add custom fields in key/value pairs like any other custom fields on any other Page or Post.</p>
<p>Make sure to note the ID of this Page. We&#8217;ll need that ID for the custom functions we are about to write, but you can also use it to exclude this page from any dynamic navigation and such, as it&#8217;s not really meant for public viewage.</p>
<p><img src="http://digwp.com/wp-content/blog-images/idvalueofpage.png" width="473" height="39" alt="" title="" /></p>
<h3>2. Create Generic Function</h3>
<p>The built-in WordPress <a href="http://codex.wordpress.org/Function_Reference/get_post_meta">get_post_meta</a> function accepts any Post ID and any key value. So we&#8217;ll add a new function to our theme&#8217;s functions.php file that generically returns values for keys we pass it. The Page ID will be hard-coded, equal to the value we just noted down.</p>
<pre><code>function global_custom_field($key) {
   $output = get_post_meta(677, $key, true);
   echo $output;
}</code></pre>
<h3>3. Create a Shortcode Function</h3>
<p>With our generic function, we can already use it just as-is in our templates. Without a special plugin though, you can&#8217;t execute PHP functions in the body of articles though. We can be even smarter though, and create a shortcode function for use in our content. </p>
<p>More stuff for your functions.php file:</p>
<pre><code>function gcf_func($atts) {
    extract(shortcode_atts(array(
		'key' =&gt; 'amazon_id'  // default value if none supplied
    ), $atts));
    return global_custom_field($key);
}
add_shortcode('global_custom_field', 'gcf_func');</code></pre>
<h3>4. Use it!</h3>
<p>Now anywhere in our template we wish to call in the value of a global custom field, we just pass the function the key value and we get back our value:</p>
<pre><code>echo global_custom_field("amazon_id");</code></pre>
<p>Or right inside our posts content:</p>
<pre><code>[global_custom_field key="amazon_id"]</code></pre>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/09/global-custom-fields/">Permalink</a> | <a href="http://digwp.com/2009/09/global-custom-fields/#comments">12 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/09/global-custom-fields/&title=Global Custom Fields">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/custom-fields/" rel="tag">custom-fields</a>, <a href="http://digwp.com/tag/echo/" rel="tag">echo</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/shortcode/" rel="tag">shortcode</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/09/global-custom-fields/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to Display a Copyright as a Range of Dates</title>
		<link>http://digwp.com/2009/08/range-copyright-dates/</link>
		<comments>http://digwp.com/2009/08/range-copyright-dates/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 06:06:44 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[copyright]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[footer]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=604</guid>
		<description><![CDATA[Technically, your work is protected under copyright &#8220;the moment it is created and fixed in a tangible form that it is perceptible either directly or with the aid of a machine or device.&#8221; [1] Registration of your copyrighted work is not required [2], but you should include a copyright notice on all published works [3]. [...]]]></description>
			<content:encoded><![CDATA[<p>Technically, your work is protected under copyright &ldquo;the moment it is created and fixed in a tangible form that it is perceptible either directly or with the aid of a machine or device.&rdquo; <small>[1]</small> Registration of your copyrighted work is not required <small>[2]</small>, but <strong>you should include a copyright notice on all published works</strong> <small>[3]</small>. </p>
<p><a href="http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/" title="Dynamic Copyright in your WordPress Footer">Displaying a copyright statement in the footer of your web pages</a> is easily done with something like this:</p>
<p><span id="more-604"></span></p>
<pre><code>Copyright &amp;copy; &lt;?php echo date('Y'); ?&gt; Digging into WordPress</code></pre>
<p>This code will output the following text:</p>
<p>Copyright &copy; 2009 Digging into WordPress</p>
<p>I think most of us are familiar with this technique, as it would be a total pain to <em>manually</em> update the copyright date on all of your sites <em>every</em> year. </p>
<p>But what if you want to display your site&rsquo;s copyright statement as a range of dates instead of just the current year? Many sites do this, and I am guessing that they do something like this in their source code:</p>
<pre><code>Copyright &amp;copy; 2008 - &lt;?php echo date('Y'); ?&gt; Digging into WordPress</code></pre>
<p>While this method certainly works, it would be better to automate the process and have the range of dates displayed dynamically. This would be especially helpful for publicly released themes, where you want to minimize the amount of &ldquo;fiddling&rdquo; involved with the setup and configuration process.</p>
<p>To display a copyright as a range of dates for your theme, add the following function to your theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>&lt;?php // display range of dates for copyright @ digwp.com
function copyrightDate() {
	global $wpdb;
	$copyright_dates = $wpdb-&gt;get_results("
		SELECT 
			YEAR(min(post_date_gmt)) AS firstdate, 
			YEAR(max(post_date_gmt)) AS lastdate 
		FROM 
			$wpdb-&gt;posts
	");
	if($copyright_dates) {
		$copyright = "Copyright &amp;copy; " . $copyright_dates[0]-&gt;firstdate;
		if($copyright_dates[0]-&gt;firstdate != $copyright_dates[0]-&gt;lastdate) {
			$copyright .= '-' . $copyright_dates[0]-&gt;lastdate;
		}
		echo $copyright . "&amp;nbsp;" . get_bloginfo('name');
	}
}
add_filter('wp_footer', 'copyrightDate');
?&gt;</code></pre>
<p>That&rsquo;s all there is to it. Nothing else needs to be done in order for this code to output the something similar to the following:</p>
<p>Copyright &copy; 2008-2009 Digging into WordPress</p>
<p>If your site is less than a year old, the function will simply print a single-year copyright date:</p>
<p>Copyright &copy; 2009 Digging into WordPress</p>
<p>By default, this function will display this information wherever the following hook is located in your theme:</p>
<pre><code>&lt;?php wp_footer(); ?&gt;</code></pre>
<p>If this hook is not present, of if you would like to customize the location of the copyright statement, simply call the function anywhere in your theme with the following tag:</p>
<pre><code>&lt;?php copyrightDate(); ?&gt;</code></pre>
<p>Depending on your theme setup, if you call the function directly, you may want to comment out the last line (i.e., <code>add_filter()</code>) in the function itself to prevent duplicate output.</p>
<h4>References</h4>
<p>[1] <a href="http://www.copyright.gov/help/faq/faq-general.html" title="Copyright in General">http://www.copyright.gov/help/faq/faq-general.html</a><br />
[2] Unless you wish to bring a lawsuit for infringement of a U.S. work.<br />
[3] Source: <a href="http://www.entrepreneurpress.com/cgi-bin/books/00320.html" title="Business &#038; Small Business Bookstore - Intellectual Property - Entrepreneurpress.com">Intellectual Property: Patents, Trademarks, Copyrights and Trade Secrets</a></p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/08/range-copyright-dates/">Permalink</a> | <a href="http://digwp.com/2009/08/range-copyright-dates/#comments">12 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/08/range-copyright-dates/&title=How to Display a Copyright as a Range of Dates">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/copyright/" rel="tag">copyright</a>, <a href="http://digwp.com/tag/date/" rel="tag">date</a>, <a href="http://digwp.com/tag/echo/" rel="tag">echo</a>, <a href="http://digwp.com/tag/footer/" rel="tag">footer</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/08/range-copyright-dates/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Dynamic Copyright in your WordPress Footer</title>
		<link>http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/</link>
		<comments>http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/#comments</comments>
		<pubDate>Fri, 29 May 2009 23:44:16 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[copyright]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[footer]]></category>

		<guid isPermaLink="false">http://modernwordpress.com/?p=13</guid>
		<description><![CDATA[Many footers on websites contain text like &#8220;&#169; 2009 Your Website&#8221;. A good measure, surely. We can use some classic PHP and a built-in WordPress function to make this bit of text dynamic so that it will never need to be tampered with manually again. &#60;p&#62; &#38;copy; &#60;?php echo date("Y"); echo " "; echo bloginfo('name'); [...]]]></description>
			<content:encoded><![CDATA[<p>Many footers on websites contain text like &#8220;&copy; 2009 Your Website&#8221;. A good measure, surely. We can use some classic PHP and a built-in WordPress function to make this bit of text dynamic so that it will never need to be tampered with manually again.</p>
<pre><code>&lt;p&gt;
   &amp;copy; &lt;?php echo date("Y"); echo " "; echo bloginfo('name'); ?&gt;
&lt;/p&gt;</code></pre>
<p>The year will always be the current year, based on your server&#8217;s set time. The text will come directly from the Blog Title setting in <code>Settings &gt; General</code>.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/">Permalink</a> | <a href="http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/#comments">3 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/&title=Dynamic Copyright in your WordPress Footer">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/copyright/" rel="tag">copyright</a>, <a href="http://digwp.com/tag/date/" rel="tag">date</a>, <a href="http://digwp.com/tag/echo/" rel="tag">echo</a>, <a href="http://digwp.com/tag/footer/" rel="tag">footer</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/05/dynamic-copyright-in-your-wordpress-footer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

