Post by JohnnyO » Tue Sep 16, 2008 2:09 pm

I am trying to get the output of the categories in this format

Code: Select all

<ul class="">
  <li>
  <a href="category1">category 1</a>
    <ul>
      <li><a href="category1.1">category 1.1</a></li>
      <li><a href="category1.2">category 1.2</a></li>
      <li><a href="category1.3">category 1.3</a></li>
    </ul>
  </li>
  <li>
  <a herf="category2"
</ul>
And this is what I have in my modules/category.tpl

Code: Select all

<div class="box">
  <ul id="box_dropdown">
	<?php foreach ($categories as $category) { ?>
	<?php if ($category['indent'] == 0)
	echo "<a href=".$category['href'].">".$category['name']."</a>";

	else {
	echo "<a href=".$category['href'].">".$category['name']."</a>";
	}
	?>
	<?php } ?>
  </ul>
</div>
I'm at a loss here .. any help would be greatly appreciated! Where do I put the li's and ul's??
Last edited by JohnnyO on Tue Sep 16, 2008 2:11 pm, edited 1 time in total.

If you make it idiot proof, they will just build a better idiot.


User avatar
New member

Posts

Joined
Wed Nov 14, 2007 7:31 am
Location - Denver, CO - USA

Post by Qphoria » Tue Sep 16, 2008 7:00 pm

There are a dozen category mods out there that all do this. Some are static and show all categories at the same time. Some only show the relevant subcategories for the parent category.

For the latter, take a look at my version of the design: http://www.opencart.com/contribution/in ... tion_id/59

You can see the demo in action here (follow the 'Computer' category down the tree)

You can also search the forum for "subcategories" for other takes on the process.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by david.gilbert » Tue Sep 16, 2008 10:00 pm

Hi JohnnyO,

While the credit for this one belongs to bruce, I think this is what your after. He did that for me for a client a few weeks ago.

Code: Select all

<ul>
&nbsp; &nbsp; &nbsp; &nbsp; <?php
&nbsp; &nbsp; &nbsp; &nbsp; $prev_level = 0;
&nbsp; &nbsp; &nbsp; &nbsp; foreach ($categories as $category)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $level = $category['indent'];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($prev_level < $level)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; ?>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ul><li><a href="<?php echo $category['href']; ?>" ><?php htmlEcho( $category['name']);?></a>
<?php&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif ($prev_level > $level)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; ?>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li></ul></li><li><a href="<?php echo $category['href']; ?>" ><?php htmlEcho( $category['name']);?></a>
<?php&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; ?>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="<?php echo $category['href']; ?>" ><?php htmlEcho( $category['name']);?></a>
<?php&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $prev_level = $level;
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; ?>
&nbsp; &nbsp; &nbsp; &nbsp; </ul> 
    </ul>
-Dave

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by JohnnyO » Tue Sep 16, 2008 10:18 pm

That is great  ;D, Thanks Dave! and Bruce!

I am a noob when it comes to php

If you make it idiot proof, they will just build a better idiot.


User avatar
New member

Posts

Joined
Wed Nov 14, 2007 7:31 am
Location - Denver, CO - USA
Who is online

Users browsing this forum: No registered users and 3 guests