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

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

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