专题页该文章关联的帖子统计数量标签分享方法,该方法需修改内核文件增加字段,对升级是有一定影响。请大家当做学习借鉴!


【经验分享】专题内容页关联的帖子统计数量的方法分享(图1)


前端显示该帖子的关联统计数量:


【经验分享】专题内容页关联的帖子统计数量的方法分享(图2)



好具体方法如下:


打开:\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;

    }

}


然后在前端模板 专题内容页view_special.htm

里面 添加:{$eyou.field.aid|GetPostCount=###}


即可