这是我用tp5写的文章列表,可以参考一下
$params['post.number'] = 1;
$params['dis.hidden_user_id'] = null;
$data = Db::table("bbs_discussion_tag")
->alias('tag')
->join('bbs_discussions dis','tag.discussion_id = dis.id')
->join('bbs_posts post','dis.id = post.discussion_id')
->where($params)
->order("tag.discussion_id","desc")
->paginate(['query' => request()->param(),'list_rows'=>18],true)
->each(function($item, $key){
preg_match('/<img.*?src="(.*?)".*?>/is',$item['content'],$img);
/* preg_match('/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/',$item['content'],$img); */
if(empty($img)){
preg_match('#url="([^"]*?)"[^>]*?#is',$item['content'],$img);
}
if(empty($img)){
$img[1] = "https://cdn.52asmr.cn/2020-12-07/1607339853-284242-thequint-fit-2019-02-c49a4b20-836f-4638-97dd-8b464804872a-asmr.webp";
}
$item['cover'] = $img[1];
return $item;
});
View::assign('data',$data);