改造mod_latestnews使其输出可以显示内容中以 { mosimage }的第一张图片,效果为,文章的标题上面是一张内容里的第一张图片.
打开mod_latestnews.xml
在<params>的下一行加上:
<param name="imagewidth" type="text" default="" label="image width" description="image width" />
mod_latestnews.php
在$access = !$mainframe->getCfg( 'shownoauth' );下面增加:
$imageWidth = intval($params->get('imageWidth', 0)) ;找到
default:
//Content Items only
$query = "SELECT a.id, a.title, a.sectionid, a.catid"
在末尾中的引号前增加:
, a.images
变成:
default:
//Content Items only
$query = "SELECT a.id, a.title, a.sectionid, a.catid, a.images"
将:
$link = sefRelToAbs( 'index.php?option=com_content&task=view&id='. $row->id . $Itemid );
?>
<li class="latestnews<?php echo $moduleclass_sfx; ?>">
<a href="<?php echo $link; ?>" class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php echo $row->title; ?></a>
</li>
<?php
}
?>
</ul>
替换成:
$link = sefRelToAbs( 'index.php?option=com_content&task=view&id='. $row->id . $Itemid );
if ($row->images)
{
$width = ($imagewidth> 0) ? ' width="'.$imagewidth.'"' : '' ;
$image = explode("|", $row->images) ;
echo '<li><a href="'. $link .'">';
echo '<img src="'.$mosConfig_live_site.'/images/stories/'.$image[0].'"
echo ' alt="'.$image[2].'" border="0" '.$width.' />';
echo '<br />'. $row->title .'</a></li>';
}
else
echo '<li><a href="'. $link .'">'. $row->title .'</a></li>';
}
echo '</ul>';
?> 就可以了。为了不影响本来功能,我们可以另存为一个模块,将mod_latesnews.php另存为:mod_lastenewspic.php;mod_latesnews.xml另存为:mod_lastenewspic.xml,然后更改xml文件里的下面三项即可:
1.<name>Latest News</name>
改为
<name>Latest News Pic</name>
2.<filename module="mod_latestnews">mod_latestnews.php</filename>
改为:
<filename module="mod_latestnewspic">mod_latestnewspic.php</filename>
3.删除
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="type" type="list" default="0" label="Module Mode" description="...">
<option value="1">Content Items only</option>
<option value="2">Static Content only</option>
<option value="3">Both</option>
</param>
你也可以直接点这里下载我做好的,并且去处了用不到的代码...