Emlog实现调用分类下第一篇文章图片函数分享
# g3 f/ V& C1 G. w9 ^6 |" @效果图大家先看看
9 }+ |0 A/ a! S1 Q( O6 _4 v9 O& Q, h5 ]! n
的在模板文件下的module.php下添加如下函数- <?php //分类文章调用
1 Y; _+ e- i$ P3 F - function sort_log($sortid){* x4 h! n( X4 o' U+ Z7 H- |- _
- $db = MySql::getInstance();, X. w. O8 a: K" U) S4 d: \
- $sql = $db->query ("SELECT * FROM ".DB_PREFIX."blog WHERE sortid='$sortid' AND type='blog' AND hide='n' order by date DESC limit 0,1");! g7 H( |6 [9 M8 c, P
- $row = $db->fetch_array($sql);
; u' ^$ B* I M4 v+ U$ O& h - if (!empty($row['excerpt'])){
9 p* h6 ^' z F- o* \- q - preg_match_all("/\<img.*?src\="(.*?)"[^>]*>/i", $row['excerpt'], $match);% V$ h, K3 Y, {0 O2 d6 o
- if(empty($match[0][0]))" s* x7 U/ R1 J6 z. [; K) I. k
- {preg_match_all("/\<img.*?src\="(.*?)"[^>]*>/i", $row['content'], $match);}2 M _4 M) s- C
- }else{preg_match_all("/\<img.*?src\="(.*?)"[^>]*>/i", $row['content'], $match);}! K- K3 W( {- S, ~5 L9 Z6 t
- $logpost = !empty($row['excerpt']) ? $row['excerpt'] : ''.$row['content'].'';
. s: c* E4 W- i6 o& b, C - $num = rand(1,$imgnum);
( f! K8 M- y& F - $img = isset($match[0][0]) ? $match[0][0] : '<img src="'.TEMPLATE_URL.'images/shuyong_net/'.$num.'.jpg">';
: t6 |: F- w; P$ q. j - $content = strip_tags($logpost,'');
" k! g# Y2 m$ S% i$ a - $content = mb_substr($content,0,68,'utf-8');//
9 N4 ]$ w! [" W I9 X5 A" D - $out .='<div class="sort-tw"><div class="sort-img"><a href="'.Url::log($row['gid']).'" title="'.$row['title'].'" >'.$img.'</a></div>
1 J/ H" J! A& l: i/ u* P7 R- ` q - <div class="sort-tt"><a href="'.Url::log($row['gid']).'" title="'.$row['title'].'" >'.$row['title'].'</a></div><div class="sort-nr">'.$content.'...</div></div>
5 h! V z2 G( ~3 |+ q: l& g, { - ';
" r8 w1 R/ H3 Y9 O - $sort_log_num = $sort_log_num -1;
+ Z: z* L5 B' z, u7 ]" N - $logs = $db->query ("SELECT * FROM ".DB_PREFIX."blog WHERE sortid='$sortid' AND type='blog' AND hide='n' order by date DESC limit 1,10");//1表示从第2篇文章开始,10为数量" W7 Z; F6 E) Z- \* I# ^) U. H
- while ($trow = $db->fetch_array($logs)){
* N3 ]% O) M4 S' V0 { - $date = gmdate('m-d', $trow['date']);6 B d8 [) a8 D4 K* c
- $trow['title'] = mb_substr($trow['title'],0,180,'utf-8');
3 f+ N1 C8 A% ]5 h6 G - $out .='<li><p><a href="'.Url::log($trow['gid']).'" title="'.$trow['title'].'">'.$trow['title'].'</a></p><span>'.$date.'</span></li>
0 j1 w% y# m0 n. g# Z; l - ';/ l$ y& L; d& H6 ~, V
- }echo $out;}?>
复制代码 Emlog模板文件log_list.php下使用如下代码0 X4 F, Q, U) V% t0 R
- <span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 宋体, sans-serif; line-height: 25px;"><?php global $CACHE;$sort_cache = $CACHE->readCache('sort'); ?></span>- a7 T+ i/ a0 L- l
- <span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 宋体, sans-serif; line-height: 25px;"><?php echo $sort_cache[1]['sortname'];?>调用分类名称,其中[1]代表分类id</span># s2 Y' G5 F# e \) W1 {
- <span style="color: rgb(51, 51, 51); font-family: 微软雅黑, 宋体, sans-serif; line-height: 25px;"><?php sort_log(1); ?></span>
复制代码
) C0 R( U3 m, X6 F* E0 e$ r4 t最后写上CSS就ok,css文件自己折腾吧
) m# O3 u; z: [- Z |