x
 
Create New Page
 View Previous Changes    ( Last updated by Larry Tomlinson )

Automatically Updated Copyright

Question:

I have a copyright statement on my site that contains the current year. When the next year arrives, how can I have the copyright date ranges change automatically?

Answer:

If you are willing to “hard code” your starting copyright year (that is, you already need to cover multiple years with a fixed starting date), you can do this easily with the EE {current_time} tag:

Content © Copyright 2004 {current_time format="%Y"

Otherwise, use PHP inside of an ExpressionEngine template as follows:

<? 
$startyear 
2004
$currentyear date("Y"); 

if (
$startyear == $currentyear

echo "<div align=center>Content © $startyear - Your Name</div>\n"


else 

echo "<div align=center>Content © $startyear - $currentyear - YourName</div>\n"


?> 

You set your start date of your website, and then the current year is calculated. Depending on the values that are set, you’ll either see a single date or a date range.

You’ll need to turn on PHP in the template that contains this code. Consult the EE documentation on how to do this.

You may also do this in a “pure” EE manner, such as:

&copy{if {current_time format="%Y"== "2009"}{current_time format="%Y"}{if:else}2009 &ndash{current_time format="%Y"}{/if} Company NameAll rights reserved

In the example above, we’re comparing the current year to the start date (in this case 2009). If this is true, we only display the current date (no sense in having 2009-2009, is there?). If the current date is anything other than your start date, we assume that the current date is later than the start date, and present a range of dates.

Category:Tricks

Category:EE1

Categories: