Typecho最新热门热评文章调用api
用法就是将下面的函数放到模板函数文件里,如果存在同名函数请自行合并。json版function themeInit($archive)
{
$db = Typecho_Db::get();//数据库操作调用
if($archive->request->api){
$pagesize=8;//每页文章数量
$p=1;if($archive->request->page){$p=$archive->request->page;}
$select=$db->select('cid')->from('table.contents')
->where('table.contents.status = ?','publish')
->where('table.contents.password IS NULL')
->where('table.contents.type = ?', 'post');
if($archive->request->api=='new'){
$select=$select->order('table.contents.created', Typecho_Db::SORT_DESC);
}elseif($archive->request->api=='hot'){
$select=$select->order('table.contents.commentsNum', Typecho_Db::SORT_DESC);
}elseif($archive->request->api=='views'){
$select=$select->order('table.contents.views', Typecho_Db::SORT_DESC);
}
$select=$db->fetchAll($select->page($p,$pagesize));//分页
$lon=count($select);
for($ii=0;$ii<$lon;$ii++){
$archive->widget('Widget_Archive@indexxiu', 'pageSize=1&type=post', 'cid='.$select $ii 'cid' )->to($ji);
$b = array(
"cid" => $ji->title,
"title" => $ji->permalink,
"description" => $ji->description,
);
}
$archive->response->throwJson(array(
'status' => '200',
'data' => $b
));
}
}
html版function themeInit($archive)
{
$db = Typecho_Db::get();
if($archive->request->api){
$pagesize=8;//每页文章数量
$p=1;if($archive->request->page){$p=$archive->request->page;}
$nextpage=$p+1;
$select=$db->select('cid')->from('table.contents')
->where('table.contents.status = ?','publish')
->where('table.contents.password IS NULL')
->where('table.contents.type = ?', 'post');
if($archive->request->api=='new'){
$select=$select->order('table.contents.created', Typecho_Db::SORT_DESC);
}elseif($archive->request->api=='hot'){
$select=$select->order('table.contents.commentsNum', Typecho_Db::SORT_DESC);
}elseif($archive->request->api=='views'){
$select=$select->order('table.contents.views', Typecho_Db::SORT_DESC);
}
$select=$db->fetchAll($select->page($p,$pagesize));//分页
$lon=count($select);
for($i=0;$i<$lon;$i++){
$archive->widget('Widget_Archive@indexxiu'.$i, 'pageSize=1&type=post', 'cid='.$select $i 'cid' )->to($ji);
?>
<a class="title" href="<?php $ji->permalink() ?>" title="<?php $ji->title() ?>">
<h2><?php $ji->title() ?></h2>
</a>
<?php
if($i==$lon-1){
echo '<a class="next" href="'.Helper::options()->siteUrl.'?api='.$archive->request->api.'&page='.$nextpage.'">下页</a>';
}
}
exit;
}
}
调用方法
最新文章:https://你的域名/?api=new&page=1
热评文章:https://你的域名/?api=hot&page=1
热门文章:https://你的域名/?api=views&page=1
其中page为当前页码
需要能玩这个游戏的老手机吗?
需要付费找各类手机游戏软件刷机包吗?
微信: lost155805 QQ: 1558050515