Emlog实现调用分类下第一篇文章图片函数

2015-8-2 / 0 评论 emlog / Mrxn

本文共计 1910 字,感谢您的耐心浏览与评论.

Emlog实现调用分类下第一篇文章图片函数分享
效果图大家先看看

的在模板文件下的module.php下添加如下函数


<?php //分类文章调用
function sort_log($sortid){
$db = MySql::getInstance();
$sql = $db->query ("SELECT * FROM ".DB_PREFIX."blog WHERE sortid='$sortid' AND type='blog' AND hide='n' order by date DESC limit 0,1");
$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,$imgnum);
$img = isset($match[0][0]) ? $match[0][0] : '<img src="'.TEMPLATE_URL.'images/shuyong_net/'.$num.'.jpg" rel="external nofollow" >';
$content = strip_tags($logpost,'');
$content = mb_substr($content,0,68,'utf-8');//
$out .='<div class="sort-tw"><div class="sort-img"><a href="'.Url::log($row['gid']).'" rel="external nofollow"  rel="external nofollow"  title="'.$row['title'].'"  >'.$img.'</a></div>
<div class="sort-tt"><a href="'.Url::log($row['gid']).'" rel="external nofollow"  rel="external nofollow"  title="'.$row['title'].'" >'.$row['title'].'</a></div><div class="sort-nr">'.$content.'...</div></div>
';
$sort_log_num = $sort_log_num -1;
$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为数量
while ($trow = $db->fetch_array($logs)){
$date = gmdate('m-d', $trow['date']);
$trow['title'] = mb_substr($trow['title'],0,180,'utf-8');
$out .='<li><p><a href="'.Url::log($trow['gid']).'" rel="external nofollow"  title="'.$trow['title'].'">'.$trow['title'].'</a></p><span>'.$date.'</span></li>
';
}echo $out;}?>
Emlog模板文件log_list.php下使用如下代码
<?php global $CACHE;$sort_cache = $CACHE->readCache('sort'); ?>
<?php echo $sort_cache[1]['sortname'];?>调用分类名称,其中[1]代表分类id
<?php sort_log(1); ?>
最后写上css就ok,css文件自己折腾吧


标签: emlog

转载:转载请注明原文链接 - Emlog实现调用分类下第一篇文章图片函数


0条回应:“Emlog实现调用分类下第一篇文章图片函数”


发表评论

{view_code_no}