推荐💻好好学
Typecho笔记(20220708)
//根据cid获取自定义字段数据
function getCustom($cid, $key){
$f=Typecho\Widget::widget('Widget_Archive@'.$cid,'pageSize=1&type=post', 'cid='.$cid);
return $f->fields->$key;
}
//随机获取文章
function getRandomPosts($limit = 10)
{
$db = Typecho\Db::get();
$result = $db->fetchAll(
$db->select()->from('table.contents')
->where('status = ?', 'publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post')
->limit($limit)
->order('RAND()')
);
if ($result) {
foreach ($result as $val) {
$val = Typecho\Widget::widget('Widget_Abstract_Contents')->push($val);
$post_title = htmlspecialchars($val['title']);
$permalink = $val['permalink'];
$cid = $val['cid'];
$imageUrl=getCustom($cid, 'imageUrl');
echo '<li><a href="' . $permalink . '"title="' . $post_title . '"><div class="pic-box"><img src="' . $imageUrl . '"class="lazy"
alt="' . $post_title . '"></div></a></li>';
}
}
}
本文来自投稿,不代表本站立场,如若转载,请注明出处:https://blog.itliujia.cn/info/202207134.html