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>';
        }
    }
}
本文来自投稿,不代表本站立场,如若转载,请注明出处:http://blog.itliujia.cn/info/202207134.html
获得公众号历史文章链接
« 上一篇 06-20
Google AdSense 广告优化
下一篇 » 07-09