Created
January 21, 2012 01:58
-
-
Save betweenbrain/1650746 to your computer and use it in GitHub Desktop.
Automatically Detect and Insert Image [name based on alias] Into Joomla Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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