帝国cms文章系统模型获取文章图片作为缩略图

微信扫一扫,分享到朋友圈

帝国cms文章系统模型获取文章图片作为缩略图
收藏 00

帝国cms文章模型newstext字段默认内容存储是以文件的形式保存的,读取时候需要通过GetTxtFieldText函数读取。

参考代码

<? php
$where = 'where 1';
if ($cur_classid) {
$where = $where.
' and classid='.$cur_classid;
}
if ($cur_id) {
$where = $where.
' and id='.$cur_id;
}
$sql = $empire - > query("select id,classid,title,newstext,diggtop from {$dbtbpre}ecms_article {$where} order by lastdotime desc limit 10");
//查询新闻表最新10条记录
while ($r = $empire - > fetch($sql)) //循环获取查询记录 {
?>
< div class = "ans-item <?php if($cur_id==$r['id'])echo 'on'; ?>" > < b > <?= $r['title'] ?> < /b><div class="ans-item-answer"><?=GetTxtFieldText($r['newstext'])?></div > < div class = "identify" > < span qid = "44"
class = "prise-num" > <?= $r['diggtop'] ?> < /span><span class="job-post"><?=$public_r['sitename']?></span > < /div><span class="arrow-cont"><i class="arrow-icon"></i > < /span></div >
<? php
} ?>

 

将以下函数放入/e/class/userfun.php

function getnewsimg($rid,$n){   
    global $empire,$dbtbpre,$class_r;   
    $fr=$empire->fetch1("select newstext from {$dbtbpre}ecms_art where id='$rid'");   
    $newstext=stripslashes(GetTxtFieldText($fr['newstext']));   
    $pattern = '/<img.*?src.*?="(.*?)".*?>/i';
    preg_match_all($pattern, $newstext, $match);   
    if(count($match[1])>=$n){   
         $diypic=$match[1][$n-1];   
    }else{   
         $diypic='/e/data/images/notimg.gif';   
    }   
    return $diypic;   
}

调取

<?=getnewsimg($bqr[id],1)?>

 

一个热爱互联网的咸鱼
上一篇

帝国CMS编辑器远程保存图片失效原因汇总

你也可能喜欢

发表评论

您的电子邮件地址不会被公开。 必填项已用 * 标注

提示:点击验证后方可评论!

插入图片

热门

    抱歉,30天内未发布文章!
返回顶部