大家好,我正在尝试在以下主要类别中列出子猫:
Maincat1
-subcat
Maincat2
-subcat
请看 图片
这是列出主要猫的代码:
在 global_header.php 中
$sql_select_cats_list = $db->query("SELECT category_id, items_counter, hover_title, image_path FROM
" . DB_PREFIX . "categories WHERE parent_id=0 AND hidden=0 AND user_id=0 AND enable_auctions=1 ORDER BY order_id ASC, name ASC");
$template->set('sql_select_cats_list', $sql_select_cats_list);
$category_box_content = $template->process('categories_box.tpl.php');
$template->set('category_box_content', $category_box_content);
这是categories_box.tpl.php
<?
while ($cats_header_details = $db->fetch_array($sql_select_cats_list))
{
$category_link = process_link('categories',
array('category' => $category_lang[$cats_header_details['category_id']],
'parent_id' => $cats_header_details['category_id']));
?>
<li>
<a style="font-size: 11px; font-weight: normal; text-decoration:none;"
href="<?=$category_link;?>"
<?=((!empty($cats_header_details['hover_title'])) ? 'title="' . $cats_header_details['hover_title'] . '"' : '');?>
alt="">
<img src="<?=$cats_header_details['image_path'];?>" width="10" height="8" border="0" />
<?=$category_lang[$cats_header_details['category_id']];?>
<?=(($setts['enable_cat_counters']) ?
(($cats_header_details['items_counter']) ?
'(<strong>' . $cats_header_details['items_counter'] . '</strong>)' :
'') :
'');
?>
</a>
</li>
<?
}
?>
这是我在 function.php 上的原始函数列表类别
function category_navigator ($parent_id, $show_links = true, $show_category = true, $page_link = null, $additional_vars = null, $none_msg = null, $reverse_categories = false)
{
global $reverse_categoy_lang, $category_lang, $db;
(string) $display_output = NULL;
(int) $counter = 0;
$none_msg = ($none_msg) ? $none_msg : GMSG_ALL_CATEGORIES;
$page_link = ($page_link) ? $page_link : $_SERVER['PHP_SELF'];
if($parent_id > 0)
{
$root_id = $parent_id;
while ($root_id > 0)
{
$row_category = $db->get_sql_row("SELECT category_id, name, parent_id FROM
" . DB_PREFIX . (($reverse_categories) ? 'reverse_categories' : 'categories') . " WHERE
category_id=" . $root_id . " LIMIT 0,1");
if($counter == 0)
{
$display_output = ($reverse_categories) ? $reverse_category_lang[$row_category['category_id']] : $category_lang[$row_category['category_id']];
$display_output = (!empty($display_output)) ? $display_output : $row_category['name'];
}
else if($parent_id != $root_id)
{
$category_name = ($reverse_categories) ? $reverse_category_lang[$row_category['category_id']] : $category_lang[$row_category['category_id']];
$category_name = (!empty($category_name)) ? $category_name : $row_category['name'];
$display_output = (($show_links) ? '<a href="' . $page_link . '?parent_id=' . $row_category['category_id'] . '&name=' . sanitize_var($category_name) . ((!empty($additional_vars)) ? ('&' . $additional_vars) : '') . '">' : '') . $category_name . (($show_links) ? '</a>' : '') . ' > ' . $display_output;
}
$counter++;
$root_id = $row_category['parent_id'];
}
$display_output = (($show_links && $show_category) ? '<a href="' . $page_link . '?' . $additional_vars . '"><b> ' . GMSG_CATEGORY . ':</b></a> ' : '') . $display_output;
}
$display_output = (empty($display_output)) ? $none_msg : $display_output;
return $display_output;
}
数据库名称是:类别
table : categories
| category_id + parent_id + name |
| 1 | 0 | Flower |
| 2 | 0 | Wall Decor |
| 3 | 0 | Stylish Living |
| 4 | 1 | Mug |
| 5 | 1 | Sun Flower |
我需要帮助才能做到这一点。
导航菜单
<div id="navigation">
<ul> <li><a href="#">News</a>
<ul> <li>National News</li> <li>International News</li> <li>Sports News </li> <li>Hollywood news</li> </ul>
</li>
<li>
<a href="#">Technology</a>
<ul> <li>IT/Software </li> <li>Hardware</li> <li>Iphone</li> <li>Neuro-Science</li> </ul>
</li>
<li>
<a href="#">Sports</a>
<ul> <li>Cricket</li> <li>Tenis</li> <li>Badminton</li> <li>Hockey</li> </ul>
</li>
<li>
<a href="#">Contry</a>
<ul> <li>India</li> <li>Shree lanka </li> <li>Bangaladesh</li> <li>England</li> </ul>
</li>
</ul>
</div>
最后修改:
解决了特别感谢@furas
代码:
<div id="navigation">
<ul> <?
foreach($menu_multiarray as $main_category)
{
$cats_link = process_link('categories', array('category' => $main_category['category']['name'], 'parent_id' => $main_category['category']['category_id']));
?>
<li>
<a style="font-size: 11px; font-weight: normal; text-decoration:none;" href="<?=$cats_link;?>" <?=((!empty($main_category['hover_title'])) ? 'title="' . $main_category['hover_title'] . '"' : '');?> alt="">
<img src="<?=$main_category['image_path'];?>" width="10" height="8" border="0" /> <?=$main_category['category']['name'];?>
<?=(($setts['enable_cat_counters']) ? (($main_category['items_counter']) ? '(<strong>' . $main_category['items_counter'] . '</strong>)' : '') : '');?></a>
<?
foreach($main_category["subcategories"] as $sub_category)
{
$sub_cats_link = process_link('categories', array('category' => $sub_category['name'], 'parent_id' => $sub_category['category_id']));
?>
<ul>
<li>
<a style="font-size: 11px; font-weight: normal; text-decoration:none;" href="<?=$sub_cats_link;?>" <?=((!empty($sub_category['hover_title'])) ? 'title="' . $sub_category['hover_title'] . '"' : '');?> alt="">
<img src="<?=$sub_category['image_path'];?>" width="10" height="8" border="0" /> <?=$sub_category['name'];?>
<?=(($setts['enable_cat_counters']) ? (($sub_category['items_counter']) ? '(<strong>' . $sub_category['items_counter'] . '</strong>)' : '') : '');?></a>
</li>
</ul>
<? } ?>
</li>
<? } ?>
</ul>
</div>