Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created January 21, 2012 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betweenbrain/1650746 to your computer and use it in GitHub Desktop.
Save betweenbrain/1650746 to your computer and use it in GitHub Desktop.
Automatically Detect and Insert Image [name based on alias] Into Joomla Template
<?php
$itemId = JRequest::getInt('Itemid', 0);
if ($itemId) {
$currentAlias = JSite::getMenu()->getActive()->alias;
$altText = str_replace("-"," ",$currentAlias);
$fileTypes = array('png','jpg','jpeg','gif');
foreach ($fileTypes as $fileType) {
$headerImage = JPATH_BASE . '/images/banners/' . $currentAlias . '.' . $fileType;
if(JFile::exists($headerImage)) {
list($width, $height, $type, $attr) = getimagesize($headerImage);
echo '<img class="article-banner" src="'.JURI::base().'images/banners/' . $currentAlias . '.' . $fileType.'"'. $attr .'alt="' . $altText .'" />';
break;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment