Code: Select all
$start = 2010; // The year the site started
$current = date('Y'); // The current year
$date = ($start >= $current) ? $start : $start . '-' . $current; // If it is currently the start year, just return that. otherwise, return the the start year - the current year, e.g. 2010-2011
$template->assign_var('MYCOPYRIGHT', 'Copyright© ' . $date); // Assign that to a template variable for use in your template
Code: Select all
$start = 2010; // The year the site started
$current = date('Y'); // The current year
$date = ($start >= $current) ? $start : $start . '-' . $current; // If it is currently the start year, just return that. otherwise, return the the start year - the current year, e.g. 2010-2011
$template->assign_var('MYCOPYRIGHT', 'Copyright© 20' . $date); // Assign that to a template variable for use in your template
Code: Select all
$template->display('body');
garbage_collection();
exit_handler();
I think you may have misinterpreted the purpose of the minus sign in that codeChaosBringer wrote:Yes but by looking at that code i can see that it would only return the difference
woopsimkingdavid wrote:Yeah, ChaosBringer, I have tested the code I provided on my own server and it works as intended. I then tested your code and it outputs 202010.
The reason is that the minus sign in the code is in single quotation marks, which makes it a string instead of a mathematical operator. It doesn't take the difference of the two numbers, it just adds a - to the output. In other words, if the $start variable is the current year or is somehow after the current year, it will just output the start year (e.g. 2010). If the start year is before the current year, it will output that year, dash, the current year, e.g. 2008-2010.
includes/functions.php
, in function page_header()
they define an array with the variables that may be used at any point by a template. I just added mine in the array.Code: Select all
// The following assigns all _common_ variables that may be used at any point in a template.
$template->assign_vars(array(
'SITENAME' => $config['sitename'],
'SITE_DESCRIPTION' => $config['site_desc'],
...
'MYCURRENTYEAR' => '' . date ('Y'),
));
overall_footer.html
template.Code: Select all
Copyright 2010-{MYCURRENTYEAR}
What is wrong about automatic updating the latest year of the copyright is that probably by January 1st (wherever you live) you haven't made your work "copyrightable", you were probably sleeping or somethingYou can use a range (‘2008-2010’) instead of listing individual years (‘2008, 2009, 2010’) if and only if: 1) every year in the range, inclusive, really is a “copyrightable” year that would be listed individually; and 2) you make an explicit statement in a ‘README’ file about this usage. (http://www.gnu.org/prep/maintain/html_n ... tices.html)