Empire CMS: Different Styles for Top-Level and Active Sub-Categories

ecms class

Empire CMS can style top-level categories differently from the subcategory you're currently in.

In real projects I kept running into sites with many top-level and second-level categories, where the navigation also had to highlight the category being viewed. The old approach called each subcategory separately, which meant maintaining several templates to get the effect. To fix that, I looked around and merged the idea with an earlier method of mine (looping categories with the flexible tag and a per-category class), and adjusted it.

In the screenshot below, the current top-level category is expanded and its active subcategory is highlighted; the other top-level categories stay collapsed.

ecms menu

This code does the job:

[e:loop={"select classid,classname,islast from {$dbtbpre}enewsclass where bclassid='0' and showclass=0 order by myorder,classid ASC limit 11",0,24,0}]
<?php
$classurl=sys_ReturnBqClassname($bqr,9); // Get the category URL
$class=""; // Class for a top-level category that has children
if($GLOBALS[navclassid])
{
$fcr=explode('|',$class_r[$GLOBALS[navclassid]][featherclass]);
$topbclassid=$fcr[1]?$fcr[1]:$GLOBALS[navclassid];// Get the top-level category ID of the current category
if($bqr[classid]==$topbclassid)
{
$class=" on"; // Highlight the active category
}
}
elseif($public_r[home]==1)
{
$class="";
}
?>
                    <div class="list<?=$class?>">
                        <div class="first_cate son">
                            <a href="<?=$classurl?>" class="category_<?=$bqr[classid]?>" title="<?=$bqr[classname]?>"><?=$bqr[classname]?></a>
                            <div class="border"></div>
                        </div>
<?php
if(!$bqr[islast]) // Is it a leaf category?
{
?>
                        <div class="son_cate">
    <?php
    // Fetch the subcategories of this category
    $newsclass=$empire->query("select classid,classname from ".$dbtbpre."enewsclass where bclassid=".$bqr[classid]." order by myorder,classid asc limit 11");
    while($classr=$empire->fetch($newsclass))
    {
        $classrurl=sys_ReturnBqClassname($classr,9); // Get the subcategory URL
        $classrname="";
        if($classr[classid]==$GLOBALS[navclassid])
        {
        $classrname=" on";
        }
        ?>
                            <div class="item category_<?=$classr[classid]?><?=$classrname?>"><a href="<?=$classrurl?>" class="text-over block" title="<?=$classr[classname]?>"><?=$classr[classname]?></a></div>
    <?php
    }
    ?>
                        </div>
<?php
}
?>
                    </div>
[/e:loop]

You can also skip categories hidden in the admin panel with and showclass=0 — 0 shows, 1 hides.
Use and classid<>25 to exclude a specific category.

Leave a Comment

Comments No Comments

Table of Contents