This function is used to compare an age relative to a particular date (in this case July 1). It assumes the birthdate is being provided in the format 'dd/mm/year' but needs to be checked against 'year-mm-dd'.
function agecheck($birthDate)
{
$date = explode('/', $birthDate);
$birthDate = $date[2] . '/' . $date[1] . '/' . $date[0];
$age = floor((strtotime('2014-07-01') - strtotime($birthDate)) / 31556926);
return($age);
}
A sure sign of a site that isn't actively maintained is an out-of-date copyright date.
The easiest way to avoid this is by having the current inserted by php code. I use NoNumber's sourcer extension to allow me to insert php code into a module.
Copyright © <?php echo date('Y'); ?> <?php echo htmlspecialchars($app->getCfg('sitename')); ?>
If you are including a link to a css file in your Joomla template index.php file, you want the URL for the css to be generated automatically rather than hard coded. If you ever need to move the site to a different location this code will make sure that the css file is still properly located and loaded. This code generates the path dynamically.
<link rel="stylesheet" href="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<?php
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo '<h1>' . $article->get("title") .'<h1>';
}
?>
Occassionally I find that I need to have a branch in template file so that some pages display with a slight variation of the template. I rely on an if/then/else or switch/case construct.
The key PHP code is add the following at the start of your template:
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$temp = JRequest::getString('id');
$temp = explode(':', $temp);
$menu = JSite::getMenu();
$alias = $menu->getActive()->alias;
if ($option == 'com_content' && $view == 'category' && $temp[0])
{
$category_id = $temp[0]; //this is category ID
}
Then later you can use the following to detect all artlcle links that aren't in selected categories for example.
if($category_id !='10' && $category_id !='11' && $category_id !='12' && $category_id !='13' && $category_id !='14') : ?>