I’m unable to get the output in proper order so as to align it in this format as apple.com/sitemap. Problem I’m facing is it with tags which is used while displaying the values, I’m unable to put it in proper place.
Right now, the output is:
<ul class= "sitemap">
</ul></li><li><h2>Parent 1</h2><ul>
<li>Sub Cat 1</li>
<li>Sub Cat 2</li>
</ul></li><li><h2>Parent 2</h2><ul>
<li>Sub Cat3</li>
<li>Sub Cat 4</li>
</ul></li><li><h2>Parent 3</a></h2><ul>
If you see the ul tag is not closing properly because of which I’m unable to implement CSS..
I have created table as:
id | parent | name | url
1 | 0 | Parent1 | Link
2 | 1 | Sub Cat1| Link
3 | 2 | Sub Cat2| Link
4 | 0 | Parent2 | Link
MySQL Query to fetch the values:
$sql = 'SELECT parent,name, url FROM sitemap ORDER BY CASE WHEN parent =0 THEN id ELSE parent END , CASE WHEN parent =0 THEN 0 ELSE id END';
Lines to display the data on Page:
{foreach from=$sitemap item=c name=sitemap}
{ assign var="tmp" value= $c.parent }
{ if $tmp==0}
</ul></li><li><h2><a title="{$c.name}" href="{$c.url}">{$c.name}</a></h2><ul>
{else}
<li><a title="{$c.name}" href="{$c.url}">{$c.name}</a></li>
{/if}
{/foreach}
You’re probably looking for something along the lines of