Post by pwd » Mon Aug 29, 2011 3:28 pm

Howdy,

I'm trying to find out how to display a list of categories (parents and children in a hierarchy, with links) on header.tpl of my theme. Either by using PHP or an add-on. Any ideas?

Thanks in advance!

pwd
Newbie

Posts

Joined
Mon Aug 22, 2011 8:10 am

User avatar
Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am


Post by funrider » Mon Aug 29, 2011 5:28 pm

Does anybody know if this 'feature' is being added to a new release of OpenCart. We also used the mentioned code to create a page to show all the products on 1 page.

OpenCart is the best Webshop tool! Congratulations with releasing version 1.5


New member

Posts

Joined
Thu Jun 10, 2010 9:19 pm
Location - Netherlands

Post by pwd » Tue Aug 30, 2011 11:14 am

Out lead programmer got it sorted. This has only been tested on OpenCart 1.5.1.

Enjoy.

Code: Select all

<?php
//.. Load the category Model (model_catalog_category)
//.. Load in root categories, and loop through as "$Category"
$this->load->model('catalog/category');
?>

<ul>
<?php foreach($this->model_catalog_category->getCategories(0) as $Category): ?>
	<li><a href="index.php?route=product/category&path=<?php echo $Category['category_id'] ?>"><?php echo $Category['name'] ?></a>    
    	<?php $SubCategories = $this->model_catalog_category->getCategories($Category['category_id']) ?>
    	<?php if( count($SubCategories) > 0 ): ?>
            <ul>
            <?php foreach( $SubCategories as $SubCategory ): ?>
                <li><a href="index.php?route=product/category&path=<?php echo $SubCategory['category_id'] ?>"><?php echo $SubCategory['name'] ?></a></li>
            <?php endforeach; ?>
            </ul>
        <?php endif; ?>
	</li>
<?php endforeach; ?>
</ul>

pwd
Newbie

Posts

Joined
Mon Aug 22, 2011 8:10 am
Who is online

Users browsing this forum: No registered users and 12 guests