專題頁該文章關聯(lian)的帖子統計數量標(biao)簽分享(xiang)方法,該方法需(xu)修(xiu)改(gai)內核文件增加字段,對(dui)升級是(shi)有一定影響。請大家當做學習借(jie)鑒!
PS:此方法(fa)只對關聯的帖子有效!!!

前端顯示該帖(tie)子的關聯統計(ji)數(shu)量:

好具體方法如下:
打開(kai):\application\common.php文件(jian)
在最底下
if (!function_exists('is_template_opt'))
{
/**
* 判斷(duan)是否(fou)有權限操作模板文(wen)件
* @param [type] $ip [description]
* @return boolean [description]
*/
function is_template_opt() {
static $template_opt = null;
if (null === $template_opt) {
$file = DATA_PATH.'conf'.DS.'template_opt.txt';
$template_opt = file_exists($file) ? true : false;
}
return $template_opt;
}
}
字段下(xia)面(mian)新增如下(xia)代碼:
if (!function_exists('GetPostCount'))
{
/**
* 統(tong)計專題內容關聯的(de)文章(zhang)數
*/
function GetPostCount($aid = 0)
{
// 定(ding)義(yi)查詢條(tiao)件
$condition = ['a.aid' => $aid];
// 查詢專(zhuan)題當(dang)下符合條件的記錄
$records = \think\Db::name('special_node')->alias('a')
->join('__ARCTYPE__ b', 'b.id = a.aid', 'LEFT')
->where($condition)
->field('a.aidlist')
->select();
$totalCount = 0;
foreach ($records as $record) {
if (!empty($record['aidlist'])) {
$aidArray = explode(',', $record['aidlist']);
$totalCount += count($aidArray);
}
}
return $totalCount;
}
}
第(di)二種方法(不影響升(sheng)級(ji))就是寫在 \extend\function.php 文件也可以
if (!function_exists('GetPostCount'))
{
/**
* 統計(ji)專題內(nei)容關(guan)聯的(de)文章數
*/
function GetPostCount($aid = 0)
{
// 定義查詢條(tiao)件
$condition = ['a.aid' => $aid];
// 查詢專題(ti)當下符合條(tiao)件的(de)記(ji)錄
$records = \think\Db::name('special_node')->alias('a')
->join('__ARCTYPE__ b', 'b.id = a.aid', 'LEFT')
->where($condition)
->field('a.aidlist')
->select();
$totalCount = 0;
foreach ($records as $record) {
if (!empty($record['aidlist'])) {
$aidArray = explode(',', $record['aidlist']);
$totalCount += count($aidArray);
}
}
return $totalCount;
}
}
添加在(zai)最底(di)部的最后一個(ge)"}”前面
然后在前(qian)端(duan)模板 專題內容頁view_special.htm
里面 添加:{$eyou.field.aid|GetPostCount=###}
即可
======同樣方法:所(suo)有訂單統計數量------
(不影響升級)就(jiu)是寫在(zai) \extend\function.php 文(wen)件也可(ke)以
if (!function_exists('GetShopCout')) {
/**
* 統計 shop_order 表(biao)的(de)數(shu)據數(shu)量
*/
function GetShopCout($order_id = 0)
{
try {
// 使用 Db 類統計 shop_order 表的數據數量
$totalCount = \think\Db::name('shop_order')->count('order_id');
} catch (\Exception $e) {
// 若(ruo)出現異常,將總數設為 0
$totalCount = 0;
}
return $totalCount;
}
}
前端標簽:
{$eyou.field.order_id|GetShopCout=###}
