帝国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)?>