新闻分类名称后面显示该分类下的新闻数量
更新时间:2024-12-17 14:45:23
编辑:保利尼奥
浏览:284
public function lists($table = 'product', $parentId = 0, $orderby = 'asc')
{
static $data = null;...
public function lists($table = 'product', $parentId = 0, $orderby = 'asc')
{
static $data = null;
if (isset($data[$table][$parentId])) {
return $data[$table][$parentId];
}
self::$obj = $GLOBALS['db'];
self::$urlpath = defined('M_PATH_URL') ? M_PATH_URL : PATH_URL;
self::$city_one = $GLOBALS['city_one'] ?? [];
self::$fnames = $GLOBALS['fnames'] ?? null;
$model = $table == 'info' ? 'news' : $table;
$nodes = $this->getAllCateGories($table, $orderby);
foreach ($nodes as $key => $value) {
$nodes[$key]['target'] = intval($value['target']) == 2 ? '_blank' : '';
if($table == 'product' || $table == 'news'){
$nodes[$key]['cname'] = Core_Fun::quChong($nodes[$key]['cname']);
}
$nodes[$key]['img'] = $value['img'] ?: PATH_URL."admin/assets/images/nopic.jpg";
$cityPre = '';
if(empty(self::$fnames)){
if (!empty(self::$city_one) && $table == 'product') {
$cityPre = self::$city_one['en'].'_';
}elseif(!empty(self::$city_one) && $table == 'news'){
$cityPre = self::$city_one['en'].'_';
}
}
if ($table == 'download' || $table == 'job') {
$nodes[$key]['url'] = $value['linkurl'] ?: frontendUrl(self::$urlpath.$model, ($value['slug'] ?:$value['cid']).'/');
} else {
$nodes[$key]['url'] = $value['linkurl'] ?: frontendUrl(self::$urlpath.$model, $cityPre.($value['slug'] ?:$value['cid']).'/');
}
// 新闻分类数量
if ($table == 'news') {
$nodes[$key]['count'] = $this->getcount($value['cid']);
}
}
$data[$table][$parentId] = (new PHPTree)->getTree($nodes, $parentId);
return $data[$table][$parentId];
}
// 获取数量
public static function getcount($cid)
{
self::$obj = $GLOBALS['db'];
$searchsql = " WHERE v.flag=1";
if(intval($cid)>0)
{
$childs_sql = (new Core_Mod)->build_childsql("newscate","v",intval($cid),"");
if(Core_Fun::ischar($childs_sql)) {
$searchsql .= " AND (v.cid='".intval($cid)."'".$childs_sql.")";
} else {
$searchsql .= " AND v.cid='".intval($cid)."'";
}
}
$sql = "SELECT * FROM " . DB_PREFIX. "news as v".$searchsql." ORDER BY orders";
return count(self::$obj->getall($sql));
}