最新置顶头条文章标题加摘要显示的效果,把以下代码复制到module.php里面,如需调用分类置顶文章请把top='y'改为sortop='y'即可
代码语言:javascript复制<?php
//首页置顶头条,不带图片
function sheli_zdLog() {
$db = MySql::getInstance();
$sql = "SELECT gid,title,content,date FROM ".DB_PREFIX."blog WHERE type='blog' and top='y' ORDER BY `top` DESC ,`date` DESC LIMIT 0,1";
$list = $db->query($sql);
while($row = $db->fetch_array($list)){
//$row['content'] = htmlspecialchars($row['content']);
$row['content'] = strip_tags($row['content']);?>
<h1><a href="<?php echo Url::log($row['gid']); ?>" title="<?php echo $row['title']; ?>" target="_blank"><?php echo $row['title']; ?></a></h1>
<span class="note"><?php echo mb_substr($row['content'],0,85,'utf-8'); ?>...</span><a href="<?php echo Url::log($row['gid']); ?>" target="_blank">阅读全文>></a>
<?php } ?>
<?php } ?>
如果需要带图片请使用下面代码放入module.php中,如需调用首页置顶文章请把sortop='y'改为top='y'即可
代码语言:javascript复制<?php //分类置顶头条,带图片
function sheli_zdLog(){ $db = MySql::getInstance(); $sql = $db->query ("SELECT * FROM ".DB_PREFIX."blog inner join ".DB_PREFIX."sort WHERE hide='n' AND type='blog' AND sortop='y' AND sortid=sid order by date DESC limit 0,5"); while($row = $db->fetch_array($sql)){ if (!empty($row['excerpt'])){ preg_match_all("/<img.*?src="(.*?)"[^>]*>/i", $row['excerpt'], $match); if(empty($match[0][0])) { preg_match_all("/<img.*?src="(.*?)"[^>]*>/i", $row['content'], $match); } }else{ preg_match_all("/<img.*?src="(.*?)"[^>]*>/i", $row['content'], $match); } $logpost = !empty($row['excerpt']) ? $row['excerpt'] : ''.$row['content'].''; $num = rand(1,3); $img = isset($match[0][0]) ? $match[0][0] : '<img src="'.TEMPLATE_URL.'images/shuyong_net/'.$num.'.jpg">'; $date = gmdate('Y年m月d日', $row['date']); $content = strip_tags($logpost,''); $content = mb_substr($content,0,250,'utf-8');$comment = ($row['comnum'] != 0) ? '被吐槽<span>'.$row['comnum'].'</span>次' : '暂无吐槽'; $gid = $row['gid']; $tag = $db -> query("SELECT * FROM ".DB_PREFIX."tag WHERE gid LIKE '%,$gid,%'"); $out .='
<div class="flash_img2">
<div class="hdp_img"><a href="'.Url::log($row['gid']).'" title="'.$row['title'].'" >'.$img.'</a></div>
<div class="hdp"><h4><a href="'.Url::log($row['gid']).'" title="'.$row['title'].'">'.$row['title'].'</a></h4>
<h5>日期:'.$date.' 分类:<a href="'.Url::sort($row['sortid']).'" title="查看 '.$row['sortname'].' 中的全部文章" rel="category tag">'.$row['sortname'].'</a> 共被围观 '.$row['views'].' 次 '.$comment.'</h5>
<h6>'.$content.'...</h6></div></div>
'; } echo $out; }?>
以上未提供css代码,请自行折腾