zblogphp微信小程序获取文章列表代码
新建一个php文件,放到根目录(或者其他任意目录,但require的文件路径需要改下)。
使用方法(假设新建的文件是a.php):
var that = this wx.request({ url: 'https://www.songzhenjiang.cn/a.php?page=1&cate=1$search=搜索', success: function (res) { that.setData({ zhihu: res.data }) } })
传递的参数为page(第几页)、cate(哪个分类)、search(关键词搜索)。
调用方式:
<view class="container log-list"> <block wx:for="{{zhihu.data}}" wx:for-item="log"> <text class="log-item">{{index + 1}}. {{log.title}}</text> </block> </view>
服务端代码(a.php)
<?php require './zb_system/function/c_system_base.php'; require './zb_system/function/c_system_admin.php'; $zbp->Load(); $page = (int)GetVars('page', 'get'); $cate = (int)GetVars('cate', 'get'); $search = GetVars('search', 'get'); if(!$page) $page = 1; if(!$cate) $cate = null; if(!$search) $search = null; if($search=='undefined') $search = null; $array=GetListapi($page,$cate,$search); foreach($array as $related){ $related->imgs=$related->Metas->pic; $related->YmdTime=$related->Time('Y年m月d日'); $aa['date'][]=$related->GetData(); } $aa['p']=$page; $array=json_encode($aa); print_r($array); function GetListapi($page = 1, $cate = null, $search = null, $option = null) { global $zbp; $list = array(); if (!is_array($option)) { $option = array(); } if (!isset($option['only_ontop'])) { $option['only_ontop'] = false; } if (!isset($option['only_not_ontop'])) { $option['only_not_ontop'] = false; } if (!isset($option['has_subcate'])) { $option['has_subcate'] = false; } if (!isset($option['is_related'])) { $option['is_related'] = false; } if ($option['is_related']) { $at = $zbp->GetPostByID($option['is_related']); $tags = $at->Tags; if (!$tags) { return array(); } $count = $count + 1; } $w = array(); if ($option['only_ontop'] == true) { $w[] = array('=', 'log_IsTop', 1); } elseif ($option['only_not_ontop'] == true) { $w[] = array('=', 'log_IsTop', 0); } $w[] = array('=', 'log_Status', 0); if (!is_null($cate)) { $category = new Category; $category = $zbp->GetCategoryByID($cate); if ($category->ID > 0) { if (!$option['has_subcate']) { $w[] = array('=', 'log_CateID', $category->ID); } else { $arysubcate = array(); $arysubcate[] = array('log_CateID', $category->ID); foreach ($zbp->categories[$category->ID]->ChildrenCategories as $subcate) { $arysubcate[] = array('log_CateID', $subcate->ID); } $w[] = array('array', $arysubcate); } } else { return array(); } } if (is_string($search)) { $search = trim($search); if ($search !== '') { $w[] = array('search', 'log_Content', 'log_Intro', 'log_Title', $search); } else { return array(); } } $select = '*'; $order = array('log_PostTime' => 'DESC'); $aa=$zbp->managecount; $count = array(($page - 1) * $aa, $aa); $list = $zbp->GetArticleList($select, $w, $order, $count, null, false); if ($option['is_related']) { foreach ($list as $k => $a) { if ($a->ID == $option['is_related']) { unset($list[$k]); } } if (count($list) == $count) { array_pop($list); } } return $list; }
文章列表PHP微信小程序微信小程序百度小程序ZBlog