模板的module.php文件中放入如下代码:- <?php //调用分类文章,图文显示
9 [3 G, Y* L. A$ r2 c - function sheli_tw($sort, $num){$db = MySql::getInstance();& J, ?0 z) x, w2 s7 {5 s- f# U4 u
- $sql = "SELECT gid,title,date,content,sortid,views,comnum FROM ".DB_PREFIX."blog WHERE sortid=".$sort." AND hide='n' ORDER BY `date` DESC LIMIT 0,$num";
! C t A# X3 w9 a, o - $go = $db->query($sql);while($row = $db->fetch_array($go)){
& J* `" i% i: u' I( c - $img_url = TEMPLATE_URL.'images/sheli.jpg';//无图片时显示$ ^- F' b4 \8 w
- if(pic_thumb($row['content'])){$img_url = pic_thumb($row['content']);//查找正文第一张图片8 c5 M2 E% g2 Z
- }elseif(picthumb($row['gid'])){$img_url = picthumb($row['gid']);//查找附件第一张图片8 O5 z- n$ b N' ?! A2 w/ @; ^* P1 `
- }else{$img_url;}?>, r4 y" I5 O$ F5 j$ S) N4 v1 I
- <li><p><a href="<?php echo Url::log($row['gid']);?>"><img src="<?php echo $img_url;?>" /></p><span><?php echo $row['title'];?></a></span></li>4 D9 M- S/ ^: k# T+ E) \( x' N
- <?php }}function picthumb($blogid) {$db = MySql::getInstance();$sql = "SELECT * FROM ".DB_PREFIX."attachment WHERE blogid=".$blogid." AND (`filepath` LIKE '%jpg' OR `filepath` LIKE '%gif' OR `filepath` LIKE '%png') ORDER BY `aid` ASC LIMIT 0,1";$imgs = $db->query($sql);while($row = $db->fetch_array($imgs)){$pict.= ''.BLOG_URL.substr($row['filepath'],3,strlen($row['filepath'])).'';}return $pict;}function pic_thumb($content){preg_match_all("/\<img.*?src\="(.*?)"[^>]*>/i", $content, $img);$imgsrc = !empty($img[1]) ? $img[1][0] : '';if($imgsrc):return $imgsrc;endif;}?>
复制代码 调用方式:<?php sheli_tw(1,10);?>;其中1表示分类id,10表示数量" K* r# Z. d+ T$ l- |+ P
|