<?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>WP First Aid &#187; dynamic_copyright</title>
	<atom:link href="http://wpfirstaid.com/tag/dynamic_copyright/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpfirstaid.com</link>
	<description>It&#039;s WordPress ... anything is possible!</description>
	<lastBuildDate>Tue, 17 Jan 2012 16:47:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dynamic Copyright Revisited</title>
		<link>http://wpfirstaid.com/2011/06/dynamic-copyright-revisited/</link>
		<comments>http://wpfirstaid.com/2011/06/dynamic-copyright-revisited/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 16:55:50 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[apply_filters]]></category>
		<category><![CDATA[bns_dynamic_copyright]]></category>
		<category><![CDATA[dynamic_copyright]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=1031</guid>
		<description><![CDATA[An updated version of the dynamic copyright function found in BuyNowShop.com themes by Cais.]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote an article about a function to generate a <a title="Dynamic Copyright" href="http://wpfirstaid.com/2010/02/dynamic-copyright/">dynamic copyright</a> to display in themes.  Although I imagine the function can be adapted to be used elsewhere, the original intent was to place the function call in the footer of any given theme.</p>
<p>The function itself can be found in all the themes currently available from <a title="Cais' Profile at WordPress.org" href="http://profiles.wordpress.org/users/cais">Cais</a> at <a title="BuyNowShop.com" href="http://buynowshop.com">BuyNowShop.com</a> via the <a title="WordPress" href="http://wordpress.org">WordPress</a> Extend <a title="WordPress Extend Themes repository" href="http://wordpress.org/extend/themes/">Themes repository</a>. There have been a few minor changes to the function since it was introduced; and, it is just recently undergoing much more dramatic changes.</p>
<p>That being the case, I thought this would be a great opportunity to revisit the function and discuss what has changed since the last time I wrote about it here.</p>
<div class="aside-toggler closed"><span class="open-aside bns-dynamic-copyright-code">To see the <em>BNS Dynamic Copyright code</em> click here.</span><span class="close-aside bns-dynamic-copyright-code">To hide the <em>BNS Dynamic Copyright code</em> click here.</span>
                         </div><div class="bnsia aside bns-dynamic-copyright-code closed"></p>
<pre class="brush: php; title: ; notranslate">// Start BNS Dynamic Copyright
if ( ! function_exists( 'bns_dynamic_copyright' ) ) {
  function bns_dynamic_copyright( $args = '' ) {
      $initialize_values = array( 'start' =&gt; '', 'copy_years' =&gt; '', 'url' =&gt; '', 'end' =&gt; '' );
      $args = wp_parse_args( $args, $initialize_values );

      /* Initialize the output variable to empty */
      $output = '';

      /* Start common copyright notice */
      empty( $args['start'] ) ? $output .= sprintf( __('Copyright') ) : $output .= $args['start'];

      /* Calculate Copyright Years; and, prefix with Copyright Symbol */
      if ( empty( $args['copy_years'] ) ) {
        /* Get all posts */
        $all_posts = get_posts( 'post_status=publish&amp;order=ASC' );
        /* Get first post */
        $first_post = $all_posts[0];
        /* Get date of first post */
        $first_date = $first_post-&gt;post_date_gmt;

        /* First post year versus current year */
        $first_year = substr( $first_date, 0, 4 );
        if ( $first_year == '' ) {
          $first_year = date( 'Y' );
        }

      /* Add to output string */
        if ( $first_year == date( 'Y' ) ) {
        /* Only use current year if no posts in previous years */
          $output .= ' &amp;copy; ' . date( 'Y' );
        } else {
          $output .= ' &amp;copy; ' . $first_year . &quot;-&quot; . date( 'Y' );
        }
      } else {
        $output .= ' &amp;copy; ' . $args['copy_years'];
      }

      /* Create URL to link back to home of website */
      empty( $args['url'] ) ? $output .= ' &lt;a href=&quot;' . home_url( '/' ) . '&quot; title=&quot;' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '&quot; rel=&quot;home&quot;&gt;' . get_bloginfo( 'name', 'display' ) .'&lt;/a&gt;  ' : $output .= ' ' . $args['url'];

      /* End common copyright notice */
      empty( $args['end'] ) ? $output .= ' ' . sprintf( __('All rights reserved.') ) : $output .= ' ' . $args['end'];

      /* Construct and sprintf the copyright notice */
      $output = sprintf( __('&lt;span id=&quot;bns-dynamic-copyright&quot;&gt; %1$s &lt;/span&gt;&lt;!-- #bns-dynamic-copyright --&gt;'), $output );
      $output = apply_filters( 'bns_dynamic_copyright', $output, $args );

      echo $output;
  }
}
// End BNS Dynamic Copyright
</pre>
<p></div><script type="text/javascript">
            /* <![CDATA[ */
            jQuery( document ).ready( function(){
                jQuery( ".aside-toggler" ).click( function(){
                    jQuery( this ).toggleClass( "open" ).toggleClass( "closed" ).next( ".aside" ).slideToggle( "slow", function(){
                        jQuery( this ).toggleClass( "open" ).toggleClass( "closed" );
                    });
                });
            });
            /* ]]&gt; */
            </script>
<p>What&#8217;s changed:</p>
<ol>
<li>A `function_exists` conditional check has been added</li>
<li>Better internationalization string formating has been applied.</li>
<li>Default arguments have been set to generate a common notice.</li>
<li>The `apply_filters` function has been implemented to allow for easier customization.</li>
</ol>
<p>Also to note, the defaults are now written slightly different than the orginal generated copyright notice structure. The following are the current defaults:</p>
<ul>
<li>&#8216;start&#8217; =&gt; &#8220;Copyright&#8221;</li>
<li>&#8216;copy_years&#8217; =&gt; the copyright symbol + the dynamically generated years with published posts</li>
<li>&#8216;url&#8217; =&gt; points to the top level domain with the web site title as anchor text</li>
<li>&#8216;end&#8217; =&gt; &#8220;All Rights Reserved.&#8221;</li>
</ul>
<p>All of these paramters are now easily customized using the common WordPress structure, for example:</p>
<pre class="brush: plain; title: ; notranslate">bns_dynamic_copyright( 'start=Mine, All Mine!&amp;end=This means you, scrapers!' );</pre>
<p>&#8230; would produce the following for this site (as of this writing):</p>
<blockquote><p>Mine, All Mine! © 2009-2011 <a title="WP First Aid" href="../" rel="home">WP First Aid</a> This means you, scrapers!</p></blockquote>
<p>Of course, the above may not be appropriate for your own website &#8230; or maybe it is.</p>
<p>All the same, feel free to implement this updated function; and, don&#8217;t forget to look for it in the next releases of themes from <a title="BuyNowShop.com" href="http://buynowshop.com">BuyNowShop.com</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2011/06/dynamic-copyright-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Copyright</title>
		<link>http://wpfirstaid.com/2010/02/dynamic-copyright/</link>
		<comments>http://wpfirstaid.com/2010/02/dynamic-copyright/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 23:36:43 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[bns_dynamic_copyright]]></category>
		<category><![CDATA[dynamic_copyright]]></category>
		<category><![CDATA[get_posts]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=363</guid>
		<description><![CDATA[Add a dynamic copyright function to your WordPress theme. Just use the sample code and instructions in this post.]]></description>
			<content:encoded><![CDATA[<p>At the bottom of most blogs you will find the commonplace copyright notice that may look something like this:</p>
<blockquote><p>Copyright &copy; 2010 <strong>WP First Aid</strong> All rights reserved.</p></blockquote>
<p>Which begs the question, what about those posts made before the year 2010? This is where a dynamic copyright function would come in very handy. It would be more correct to have this display in the footer:</p>
<blockquote><p>Copyright &copy; 2009-2010 <strong>WP First Aid</strong> All rights reserved.</p></blockquote>
<p>Most <a href="http://wordpress.org/">WordPress</a> <a href="http://wordpress.org/extend/themes/">themes</a> will include, at a minimum, code that will generate a <em>current year</em> copyright statement, perhaps something along these lines:</p>
<pre class="brush: xml; title: ; notranslate">&lt;?php _e( 'Copyright &amp;copy; ' ); ?&gt;
&lt;?php echo date( 'Y' ); ?&gt;
&lt;strong&gt; &lt;?php bloginfo( 'name' ); ?&gt; &lt;/strong&gt;
&lt;?php _e( 'All rights reserved.' ); ?&gt;</pre>
<p>To make this code into a function and add some dynamics lets start with a simple PHP construct:</p>
<pre class="brush: php; title: ; notranslate">function dynamic_copyright() {
  // code goes here
}</pre>
<p>To get the first year a post was written on the blog we need to find the first post. This can be done with this code snippet:</p>
<pre class="brush: php; first-line: 2; title: ; notranslate">
  $all_posts = get_posts( 'order=ASC' );
  $first_post = $all_posts[0];
  $first_date = $first_post-&gt;post_date_gmt;
</pre>
<p>We started by getting all of the posts with the <a href="http://codex.wordpress.org/Function_Reference/get_posts">get_posts()</a> function. We assigned the first post, which is found at index 0 (zero) to its own variable. Then we assign that post&#8217;s date (in GMT) to its own variable.</p>
<p>We now have isolated the date of the first post on the blog and can perform further operations on it. The basic dynamic part of the function is complete. If the first post is removed and the &#8220;new&#8221; first post has a different date, then the above snippet will simply use the new post&#8217;s date.</p>
<p>The balance of the function is only a slight modification of the original &#8220;minimum&#8221; sample code from above:</p>
<pre class="brush: php; first-line: 5; highlight: [6]; title: ; notranslate">
  _e( 'Copyright &amp;copy; ' );
  echo substr( $first_date, 0 ,4 ) . &quot;-&quot; . date( 'Y' );
  echo ' &lt;strong&gt;' . get_bloginfo( 'name' ) . '&lt;/strong&gt; ';
  _e( 'All rights reserved.' );
</pre>
<p>The key is highlighted at line 6. We <strong>echo</strong>, or display, the first four characters of the <strong>$first_date</strong> string which is the year; add a hyphen; and, then call a standard PHP function to add the current year as a four digit representation.</p>
<p>Here is the entire <strong>dynamic_copyright()</strong> function, including comments:</p>
<pre class="brush: php; title: ; notranslate">function bns_dynamic_copyright() {
  /* Get all posts */
  $all_posts = get_posts( 'post_status=publish&amp;order=ASC' );
  /* Get first post */
  $first_post = $all_posts[0];
  /* Get date of first post */
  $first_date = $first_post-&gt;post_date_gmt;

  /* Display common footer copyright notice */
  _e( 'Copyright &amp;copy; ' );
  /* Display first post year and current year */
  if ( substr( $first_date, 0, 4 ) == date( 'Y' ) ) {
  /* Only display current year if no posts in previous years */
    echo date( 'Y' );
  } else {
    echo substr( $first_date, 0, 4 ) . &quot;-&quot; . date( 'Y' );
  }
  /* Display blog name from 'General Settings' page */
  echo ' &lt;strong&gt;' . get_bloginfo( 'name' ) . '&lt;/strong&gt; ';
  _e( 'All rights reserved.' );
}
</pre>
<p>Of course, this function is compliments of <a href="http://buynowshop.com/">BuyNowShop.com</a> and has their customary <strong>bns</strong> prefix as it will be appearing in all of their themes.</p>
<p>Just like I did, you can copy and paste the entire sample <strong>bns_dynamic_copyright()</strong> code above into your theme&#8217;s <em>functions.php</em> file; then, replace the code in your theme&#8217;s <em>footer.php</em> file that generates your old <em>static</em> copyright notice with this line of code:</p>
<pre class="brush: xml; title: ; notranslate">&lt;?php bns_dynamic_copyright(); ?&gt;</pre>
<p>Your theme will now display a dynamic copyright notice as you continue your writings for many years to come. Congratulations!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/02/dynamic-copyright/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

