Resolution process
function getRecentPosts(){ }
function getRecentPosts($obj){ }
$db = Typecho_Db::get(); $rows = $db->fetchAll($db->select('cid') ->from('table.contents') ->where('type = ? AND status = ?', 'post', 'publish') ->order('created', Typecho_Db::SORT_DESC) ->limit(10));
foreach($rows as $row){ $cid = $row['cid']; $apost = $obj->widget(' Widget_Archive@post_ '.$ cid, 'type=post', 'cid='.$ cid); $output = '<li><a href="'.$apost->permalink .'">'. $ apost->title .'</ a></li>'; echo $output; }
function getRecentPosts($obj){ $db = Typecho_Db::get(); $rows = $db->fetchAll($db->select('cid') ->from('table.contents') ->where('type = ? AND status = ?', 'post', 'publish') ->order('created', Typecho_Db::SORT_DESC) ->limit(10)); foreach($rows as $row){ $cid = $row['cid']; $apost = $obj->widget(' Widget_Archive@post_ '.$ cid, 'type=post', 'cid='.$ cid); $output = '<li><a href="'.$apost->permalink .'">'. $ apost->title .'</ a></li>'; echo $output; } }
<? php getRecentPosts($this); ?>
Optimization function
function getRecentPosts($obj,$pageSize){ Omission··· ->limit($pageSize)); Omission··· }
function getRecentPosts($obj,$pageSize){ $db = Typecho_Db::get(); $rows = $db->fetchAll($db->select('cid') ->from('table.contents') ->where('type = ? AND status = ?', 'post', 'publish') ->order('created', Typecho_Db::SORT_DESC) ->limit($pageSize)); foreach($rows as $row){ $cid = $row['cid']; $apost = $obj->widget(' Widget_Archive@post_ '.$ cid, 'type=post', 'cid='.$ cid); $output = '<li><a href="'.$apost->permalink .'">'. $ apost->title .'</ a></li>'; echo $output; } }
<? php getRecentPosts($this,10); ?>
test