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

前端顯示該帖子的關聯統計數量:

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