eyoucms有很多潛在的調(diào)用方法,比如按照年、月、日調(diào)用文章排行,這得需要懂PHP代碼的建站人員才能調(diào)用,為了方便大家易優(yōu)給大家?guī)砹瞬僮髁鞒蹋旅婢徒o大家介紹一下如何實現(xiàn)?
需要寫入的自定義php函數(shù),在“易優(yōu)cms網(wǎng)站根目錄/extend/function.php”文件內(nèi)寫入
if (!function_exists('diy_archives_list')) { // 獲取指定天數(shù)的文檔列表 function diy_archives_list($channel = 0, $day = 0, $orderby = 'aid', $limit = 10) { $where = []; !empty($channel) && $where['a.channel'] = $channel; if ($day > 0) { switch ($day) { case 1: $t = mktime(0,0,0,date('m'),date('d'),date('Y')); break; case 7: $t = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('y')); break; case 28: case 29: case 30: case 31: $t = mktime(0,0,0,date('m'),1,date('Y')); break; case 90: $t = strtotime(date('Y-m-d', strtotime(“-3 month” ))); break; case 365: case 366: $t = strtotime(date('Y-01-01')); break; default: # code… break; } $where['a.add_time'] = ['gt', $t]; } $where2 = [ 'a.arcrank' => ['gt', -1], 'a.status' => 1, 'a.is_del' => 0, 'a.lang' => get_home_lang(), ]; $where = array_merge($where, $where2); $orderby = getOrderBy($orderby, 'desc'); $result = hinkDb::name('archives')->alias('a') ->field('b.*, a.*') ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT') ->where($where) ->order($orderby) ->limit($limit) ->select(); // 獲取查詢的控制器名 $ctl_name_list = model('Channeltype')->getAll('id,ctl_name', array(), 'id'); foreach ($result as $key => $val) { $val['litpic'] = get_default_pic($val['litpic']); // 默認(rèn)封面圖 /*文檔鏈接*/ if ($val['is_jump'] == 1) { $val['arcurl'] = $val['jumplinks']; } else { $controller_name = $ctl_name_list[$val['channel']]['ctl_name']; $val['arcurl'] = arcurl('home/'.$controller_name.'/view', $val); } /*–end*/ $result[$key] = $val; } return $result; } } |
模板內(nèi)調(diào)用代碼:
{eyou:volist name=”:diy_archives_list(1,1,’click’,10)”} {$i} [ {$field.typename} ]{$field.title} ({$field.click})人閱讀發(fā)布時間:{$field.add_time|MyDate=’Y-m-d’,###} {/eyou:volist} |
(1,1,'click',10)l綠色1為頻道模型
全部:0
文章:1
產(chǎn)品:2
圖集:3
下載:4
(1,1,'click',10)中的藍(lán)色1為天數(shù):
今日:1
本周:7
本月:30
三個月:90
本年:365
全部:0
(1,1,'click',10)中的click為排序方式:
new: 按發(fā)布時間排序
click: 按點(diǎn)擊數(shù)排序
sort_order:按排序號排序
rand: 按隨機(jī)排序
(1,1,'click',10)中的10為調(diào)用條數(shù):
數(shù)值可以自定義填寫。