подкатегории выводим в категории
Модуль выводит подкатегории при переходе в категорию.
Поддерживает ЧПУ, и без ЧПУ.
В базу нет ни одного запроса.
В index.php после
$tpl->set ( '{topnews}', $topnews );
Вставляем
$tpl->set('{category_menu}', $cat_menu);
В engine/init.php в самом самом конце подключаем
include_once ENGINE_DIR . '/modules/category.php';
В шаблоне main.tpl в каком хотим месте вставляем
{topnews}
Создаем файл category.php в папке /engine/modules/ с таким содержимым
<?php
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
function CatMenuUrl( $id, $all_info ) {
if ( ! $id ) return;
$parent_id = $all_info[$id]['parentid'];
$url = $all_info[$id]['alt_name'];
while ( $parent_id ) {
$url = $all_info[$parent_id]['alt_name'] . "/" . $url;
$parent_id = $all_info[$parent_id]['parentid'];
if ( $all_info[$parent_id]['parentid'] == $all_info[$parent_id]['id'] ) break;
}
return $url;
}
#-----------------------------------------#
if ($do == "cat" and $category != '' and $subaction == '') {
if( $category) {
$cat_menu='<div class="sidebar"><div id=menu><div class="menutop"></div><div id="test1-header" class="dlet_menu_head header_highlight">Модель</div><div style="display: block;" id="test1-content" class="dlet_menu_cont"><ul>';
foreach ( $cat_info as $key => $cats ) {
$all_info[$key]['
;id'] = $cats['id'];
$all_info[$key]['
;parentid'] = $cats['parentid'];
$all_info[$key]['
;name'] = $cats['name'];
$all_info[$key]['
;alt_name'] = $cats['alt_name'];
if ( $cats['alt_name'] == $category )
{$id_now
= $cats[id];}
}
foreach ( $cat_info as $key => $cats ) {
$all_info[$key]['
;id'] = $cats['id'];
$all_info[$key]['
;parentid'] = $cats['parentid'];
$all_info[$key]['
;name'] = $cats['name'];
$all_info[$key]['
;alt_name'] = $cats['alt_name'];
if ($cats[parentid] == $id_now) { $id_category = $cats[id];
if ( $config['allow_alt_url'] == "yes" ) $cat_menu .= "<li" . $newmarker . "><h3><a href="" . $config['http_home_url'] . get_url($id_category) . "/" rel="index section"><strong>". $cats[name] . "</strong></h3></a>";
else $cat_menu.='<li><h3><a rel="index section" href="'.$config['http_home_url'].'index.php?do=cat&a
mp;category='.$cats[alt_name].'">'.$cats[name
3;."</a></h3></li>";
}
}
$cat_menu.='</ul></div><div class="menubot"></div></div></div>';
}
}
?>
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
function CatMenuUrl( $id, $all_info ) {
if ( ! $id ) return;
$parent_id = $all_info[$id]['parentid'];
$url = $all_info[$id]['alt_name'];
while ( $parent_id ) {
$url = $all_info[$parent_id]['alt_name'] . "/" . $url;
$parent_id = $all_info[$parent_id]['parentid'];
if ( $all_info[$parent_id]['parentid'] == $all_info[$parent_id]['id'] ) break;
}
return $url;
}
#-----------------------------------------#
if ($do == "cat" and $category != '' and $subaction == '') {
if( $category) {
$cat_menu='<div class="sidebar"><div id=menu><div class="menutop"></div><div id="test1-header" class="dlet_menu_head header_highlight">Модель</div><div style="display: block;" id="test1-content" class="dlet_menu_cont"><ul>';
foreach ( $cat_info as $key => $cats ) {
$all_info[$key]['
;id'] = $cats['id'];
$all_info[$key]['
;parentid'] = $cats['parentid'];
$all_info[$key]['
;name'] = $cats['name'];
$all_info[$key]['
;alt_name'] = $cats['alt_name'];
if ( $cats['alt_name'] == $category )
{$id_now
= $cats[id];}
}
foreach ( $cat_info as $key => $cats ) {
$all_info[$key]['
;id'] = $cats['id'];
$all_info[$key]['
;parentid'] = $cats['parentid'];
$all_info[$key]['
;name'] = $cats['name'];
$all_info[$key]['
;alt_name'] = $cats['alt_name'];
if ($cats[parentid] == $id_now) { $id_category = $cats[id];
if ( $config['allow_alt_url'] == "yes" ) $cat_menu .= "<li" . $newmarker . "><h3><a href="" . $config['http_home_url'] . get_url($id_category) . "/" rel="index section"><strong>". $cats[name] . "</strong></h3></a>";
else $cat_menu.='<li><h3><a rel="index section" href="'.$config['http_home_url'].'index.php?do=cat&a
mp;category='.$cats[alt_name].'">'.$cats[name
3;."</a></h3></li>";
}
}
$cat_menu.='</ul></div><div class="menubot"></div></div></div>';
}
}
?>