- (1)找到 网店根目录/
includes
/lib_article
.php
文件,并在最尾处增加以下代码(大概在行 83 处): function
GetImageSrc
($body
) {-
if
( !isset
($body
) ) { -
return
”; - }
-
else
{ -
return
$out
[4]; - }
- }
- /**
- * 按文章
ID
号或文章分类ID
号取得文章 - * @
param
array
$id
文章ID
或文章分类ID
- * @
param
string
$getwhat
以何种方式取文章.当参数为’cat
’时以文章分类ID
取,其他都以文章ID
取 - * @
param
integer
$num
控制显示多少条文章.当参数为 0 时则全部显示 - * @
param
boolean
$isrand
是否随机显示文章. - */
function
get_article_new
( $id
=array
(0), $getwhat
= ”, $num
= 0, $isrand
=false
) {- $
wherestr
= ”; - $
search
= ”; if
( $getwhat
== ‘cat
’ ){- $
search
= ‘cat_id
=’; - }
else
{- $
search
= ‘article_id
=’; - }
- $
wherestr
= $wherestr
. $search
. $id
[$i
] . ‘or
‘; - }
-
else
{ - $
wherestr
= $wherestr
. $search
. $id
[$i
]; - }
- }
- $
sql
= ‘SELECT
*FROM
‘ . $GLOBALS
[‘ecs
’]->table
(‘article
’) . - ‘
WHERE
(‘ . $wherestr
. ‘)AND
(is_open
= 1) ‘; if
( $isrand
==true
) {- $
sql
.= ‘ORDER
BY
rand
()’; - }
else
{- $
sql
.= ‘ORDER
BY
add_time
DESC
,article_type
DESC
,article_id
DESC
’; - }
if
( $num
> 0 ) {- $
sql
.= ‘LIMIT
‘ . $num
; - }
- $
res
= $GLOBALS
[‘db
’]->getAll
($sql
); - $
articles
=array
(); foreach
($res
AS
$id
=> $row
) {- $
articles
[$id
][‘title
’] = $row
[‘title
’]; - $
articles
[$id
][‘url
’] = ‘article
.php
?id
=’ . $row
[‘article_id
’]; - $
articles
[$id
][‘addtime
’] =date
($GLOBALS
[‘_CFG
’][‘date_format
’], $row
[‘add_time
’]); - $
articles
[$id
][‘content
’] = $row
[‘content
’]; - $
imgsrc
=GetImageSrc
($row
[‘content
’]); - $
articles
[$id
][‘img
’] = $imgsrc
[0]; - }
return
$articles
;- }
- (2)在模板目录的库文件目录中增加:
msg_img
.lbi
库文件 - 代码如下:
- $
this
->assign
( ‘img_art1
′,get_article_new
(array
(2),’cat
’,6) ); - ?>
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
;} - }
- –>
- {
if
$smarty
.foreach
.artimg1
.index
eq
1 } - {/
if
} - {
if
$smarty
.foreach
.artli1
.index
neq
1 } - {/
if
} - 暂无文章
- 过程一是程序的主体功能,过程二是
ecshop
模板显示时候的样式表现。 - 下面讲解一下过程二里面的重要一点的代码:
- $
this
->assign
( ‘img_art1
′,get_article_new
(array
(2),’cat
’,6) ); - 这是调用者
get_article_new
()函数,参数文章类别ID
号是 2,6 篇文章。当然,这个功能还支持随机根据这篇文章。但必须注意欧盟是一个缓存机制,可能会在选择随机发现文章中没有变化,但当打开浏览器,或刷新浏览器的缓存时间后显示已经改变了。
过程 2,第 25 行代码
{如果$smarty
。Foreach
。Artimg1
。情商指数 1}
控制显示偱环图中第一个文章。如果你想显示左边的两张图片,你可以改变显示适当的条件,等等。
过程 2,34 代码行
{如果$smarty
。Foreach
。Artli1
。指数neq
1}
这不是重复,和文章列表显示已显示图像。
其他基本上是风格布局。我直接写CSS
到库文件,然后不需要改变原来的风格。CSS
文件
转载请注明:汇站网 » ecshop教程:文章分类或ID自动取内容第一张图做为缩略图展示