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

时间:2023年12月25日

/

来源:网络

/

编辑:佚名

帝国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)?>
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。