專題頁(yè)該文章關(guān)聯(lián)的帖子統(tǒng)計(jì)數(shù)量標(biāo)簽分享方法,該方法需修改內(nèi)核文件增加字段,對(duì)升級(jí)是有一定影響。請(qǐng)大家當(dāng)做學(xué)習(xí)借鑒!
PS:此方法只對(duì)關(guān)聯(lián)的帖子有效?。?!

前端顯示該帖子的關(guān)聯(lián)統(tǒng)計(jì)數(shù)量:

好具體方法如下:
打開:\application\common.php文件
在最底下
if (!function_exists('is_template_opt'))
{
/**
* 判斷是否有權(quán)限操作模板文件
* @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;
}
}
字段下面新增如下代碼:
if (!function_exists('GetPostCount'))
{
/**
* 統(tǒng)計(jì)專題內(nèi)容關(guān)聯(lián)的文章數(shù)
*/
function GetPostCount($aid = 0)
{
// 定義查詢條件
$condition = ['a.aid' => $aid];
// 查詢專題當(dāng)下符合條件的記錄
$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;
}
}
第二種方法(不影響升級(jí))就是寫在 \extend\function.php 文件也可以
if (!function_exists('GetPostCount'))
{
/**
* 統(tǒng)計(jì)專題內(nèi)容關(guān)聯(lián)的文章數(shù)
*/
function GetPostCount($aid = 0)
{
// 定義查詢條件
$condition = ['a.aid' => $aid];
// 查詢專題當(dāng)下符合條件的記錄
$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;
}
}
添加在最底部的最后一個(gè)"}”前面
然后在前端模板 專題內(nèi)容頁(yè)view_special.htm
里面 添加:{$eyou.field.aid|GetPostCount=###}
即可
======同樣方法:所有訂單統(tǒng)計(jì)數(shù)量------
(不影響升級(jí))就是寫在 \extend\function.php 文件也可以
if (!function_exists('GetShopCout')) {
/**
* 統(tǒng)計(jì) shop_order 表的數(shù)據(jù)數(shù)量
*/
function GetShopCout($order_id = 0)
{
try {
// 使用 Db 類統(tǒng)計(jì) shop_order 表的數(shù)據(jù)數(shù)量
$totalCount = \think\Db::name('shop_order')->count('order_id');
} catch (\Exception $e) {
// 若出現(xiàn)異常,將總數(shù)設(shè)為 0
$totalCount = 0;
}
return $totalCount;
}
}
前端標(biāo)簽:
{$eyou.field.order_id|GetShopCout=###}
