<div class="section map">
    <ul>
        <a href="">Homepage</a>
        <a href="product">Products</a>
        <?php if ($tree) : ?>
            <?php
            function tree2(array &$tree, $parent = 1, $path = '')
            {
                foreach ($tree[$parent] as $c)
                {
                    echo '<a href="product/index/' . htmlspecialchars($path . $c['path']) . '">' . htmlspecialchars($c['name']) . '</a>';
                    
                    foreach (product::get_list($c['id']) as $p)
                    {
                        echo '<a href="product/view/' . htmlspecialchars($path . $c['path'] . '/' . $p['path']) . '">' . htmlspecialchars($p['name']) . '</a>';
                    }
                    
                    if (array_key_exists($c['id'], $tree))
                    {
                        tree2($tree, $c['id'], ltrim($path . '/' . $c['path'] . '/', '/'));
                    }
                }
            }
            tree2($tree, 1);
            ?>
        <?php endif; ?>
        <?php foreach ($page as $p) : ?>
            <a href="page/view/<?php echo htmlspecialchars($p['path']); ?>"><?php echo htmlspecialchars($p['name']); ?></a>
        <?php endforeach; ?>
        <a href="contact">Contact us</a>
        <?php foreach ($word as $w) : ?>
            <a href="search?search=<?php echo htmlspecialchars($w['word']); ?>"><?php echo htmlspecialchars($w['word']); ?></a>
        <?php endforeach; ?>
    </ul>
</div>