Вывод количества новостей в категориях для большого количества категорий.
Открыть файл engine/init.php
ПЕРЕД последней строкой:
?>
Вставить:
////////////////////////////////////////////////////////////////////////////////////////////////
$tcache = $config['allow_cache'];
if(!$tcache OR $tcache==1) $config['allow_cache'] = 1;
else $config['allow_cache'] = 'yes';
$cat_amounts = dle_cache("news_amount");
if(!$cat_amounts){
$cat_amounts = array();
$db->query("SELECT category,id FROM ".PREFIX."_post WHERE approve");
while($row = $db->get_row()){
if(strpos($row['category'],",")!==false){
$c = explode(",",$row['category']);
foreach($c as $k) if(!in_array($row['id'],$cat_amounts[$k])) $cat_amounts[$k][] = $row['id'];
}elseif(!in_array($row['id'],$cat_amounts[$row['category']])) $cat_amounts[$row['category']][] = $row['id'];
}
namaunt_childs();
foreach($cat_amounts as $k=>$v) $cat_amounts[$k] = count($v);
create_cache("news_amount",serialize($cat_amounts));
}else $cat_amounts = unserialize($cat_amounts);
$config['allow_cache'] = $tcache;
function namaunt_childs($parent=0){
global $cat_amounts,$cat_info;
$childs = array();
foreach($cat_info as $k=>$v){
if($v['parentid']==$parent){
$temp = namaunt_childs($k);
if(!is_array($cat_amounts[$k])) $cat_amounts[$k] = array();
$cat_amounts[$k] = array_unique(array_merge($cat_amounts[$k],$temp));
$childs = array_unique(array_merge($childs,$cat_amounts[$k]));
}
}
return $childs;
}
function namaunt($m){
global $cat_amounts,$category_id;
$id = is_array($m)?intval($m[1]):intval($m);
if($id<1){
if($category_id) $id = $category_id;
else return 0;
}
return $cat_amounts[$id];
}
////////////////////////////////////////////////////////////////////////////////////////////////
Открыть файл index.php
Найти строку:
echo $tpl->result['main'];
ПЕРЕД ней вставить:
$tpl->result['main'] = preg_replace_callback("#{namaunt=(\d+)}#i","namaunt",$tpl->result['main']);
В любом месте шаблона сайта использовать тег:
{namaunt=5}
где 5 - ID желаемой категории
{namaunt=0} - будут выводиться количество новостей из просматриваемой категории.