(1)找到 网店根目录/includes/lib_article.php文件,并在最尾处增加以下代码(大概在行83处):
function GetImageSrc($body) {
}
function get_article_new( $id = array(0), $getwhat = '', $num = 0, $isrand = false ) {
$wherestr = '';
$search = '';
if( $getwhat ==
}
else {
}
for( $i=0; $i<count($id); $i++ ) {
}
$sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('article') .
' WHERE (' . $wherestr . ') AND (is_open = 1) ';
if ( $isrand == true ) {
}
else {
}
if ( $num > 0 ) {
}
$res = $GLOBALS['db']->getAll($sql);
$articles = array();
foreach ($res AS $id => $row) {
}
return $articles;
}
(2)在模板目录的库文件目录中增加:msg_img.lbi库文件
代码如下:
<?php
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
.img_art{ width:273px; height:130px; border:#FFF solid 1px; float:left; padding-bottom:10px; overflow:hidden; }
.title { background-color:#D3C08D; height:22px; color:#765935; padding:5px 5px 0px 5px; font-weight:bold;}
.content { padding:5px;}
.Limg {width:100px; height:100px; border:#E0E0E0 solid 1px; padding:1px; text-align:center; margin-right:2px; float:left;}
.Limg img {width:100px; height:100px; border:0px; }
.rcont { width:155px; float:left;}
.rcont li {padding-left: 2em;line-height: 180%;background-image: url(images/news_arrow.gif);background-repeat: no-repeat;background-position: 12px 5px;white-space:nowrap;width:150px;text-overflow:ellipsis;overflow:hidden;}
.rcont a:visited, .rcont a:link {color: #9A6F4A;text-decoration: underline;}
.rcont a:hover {color: #9A6F4A;text-decoration: underline;}
}
-->
</style>
<div class="img_art">
<div class="title">公司新闻</div>
</div>
过程一是程序的主体功能,过程二是模板显示时候的样式表现。
下面讲解一下过程二里面的重要一点的代码:
$this->assign( 'img_art1', get_article_new(array(2),'cat',6) );
这里是调用程序的get_article_new()函数,参数意思是取文章分类ID号为2,并且取6篇.当然本函数还支持随机显示文章。但这里要注意EC是有缓存机制的,可能在选择了随机的时候没有发现文章有变化,但当重新打开浏览器或过了缓存时间后重新刷新浏览器文章显示就有变化了。
过程二,行25代码
{if $smarty.foreach.artimg1.index eq 1 }
这里控制的是显示偱环中的文章图片第一条文章。如果想左边显示两张图片,则可以适当改动要显示的条件等。
过程二,行34代码
{if $smarty.foreach.artli1.index neq 1 }
这里就是在显示文章列表时不重复已经显示过的图片。
其他基本上都是样式布局了。我是将CSS直接写进了库文件中,这样不用改动原来的STYTLE.css文件