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

前端顯(xian)示(shi)該(gai)帖(tie)子的關聯(lian)統計(ji)數量:

好具體方法如下:
打(da)開:\application\common.php文(wen)件
在最底下
if (!function_exists('is_template_opt'))
{
/**
* 判斷是否有權限(xian)操作(zuo)模板文(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;
}
}
字(zi)段下面(mian)新增如下代碼:
if (!function_exists('GetPostCount'))
{
/**
* 統(tong)計專(zhuan)題內容關聯(lian)的文章數
*/
function GetPostCount($aid = 0)
{
// 定義(yi)查(cha)詢條件
$condition = ['a.aid' => $aid];
// 查(cha)詢專題(ti)當下符合(he)條件的記錄
$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;
}
}
第二種(zhong)方法(fa)(不影響(xiang)升級)就(jiu)是寫在 \extend\function.php 文件也可(ke)以
if (!function_exists('GetPostCount'))
{
/**
* 統(tong)計專題內容關(guan)聯的(de)文章數
*/
function GetPostCount($aid = 0)
{
// 定義(yi)查(cha)詢條件
$condition = ['a.aid' => $aid];
// 查(cha)詢專題當下符合條件的記(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;
}
}
添(tian)加在(zai)最底部(bu)的(de)最后一個"}”前面
然(ran)后在前(qian)端模板(ban) 專題內容頁view_special.htm
里面 添加:{$eyou.field.aid|GetPostCount=###}
即可
======同(tong)樣方法:所有訂單統計數(shu)量------
(不影響升級)就是寫(xie)在 \extend\function.php 文件也可(ke)以
if (!function_exists('GetShopCout')) {
/**
* 統(tong)計(ji) shop_order 表的(de)數據(ju)數量
*/
function GetShopCout($order_id = 0)
{
try {
// 使用 Db 類統(tong)計 shop_order 表的數(shu)據(ju)數(shu)量
$totalCount = \think\Db::name('shop_order')->count('order_id');
} catch (\Exception $e) {
// 若出現異常,將總數設為 0
$totalCount = 0;
}
return $totalCount;
}
}
前端標簽:
{$eyou.field.order_id|GetShopCout=###}
