首先,我会尽量保持这一点。
这是一个较大的脚本的一部分,它根据用户当前在页面上的类别生成痕迹链接列表。
类似的东西:
帽子>男士>绿色
每个类别也有相应的链接,因此用户可以点击它。
我遇到的问题是,由于某些原因,我在顶级类别之前插入了当前类别的其他链接。
例如,输出应为:
<a href="categories.php?keywords_search="><b>Category:</b></a>
<a href="categories.php?parent_id=175707&name=Hats&keywords_search=" title="">Hats</a> >
<a href="categories.php?parent_id=175769&name=Mens&keywords_search=" title="">Mens</a> >
<a href="categories.php?parent_id=175828&name=Green&keywords_search=" title="">Green</a>
但我得到了这个:
<a href="categories.php?keywords_search="><b>Category:</b></a>
<a href="categories.php?parent_id=175707&name=Hats&keywords_search=" title="">Hats</a> >
<a href="categories.php?parent_id=175828&name=Green&keywords_search=" title="">
<a href="categories.php?parent_id=175769&name=Mens&keywords_search=" title="">Mens</a> >
<a href="categories.php?parent_id=175828&name=Green&keywords_search=" title="">Green</a>
</a>
请注意,不同之处在于,当前类别链接(但没有名称)几乎再次插入到顶部,此外还有最后一个链接结束标记。
可能是什么问题?我已经花了将近6个小时的时间来解决这个问题,所以如果有人能告诉我什么是错的话,我真的很感激。也许我花了太多时间看这个,而且我被困在盒子里面#34; :)
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_category_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, hover_title 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'];
$ace = $row_category['category_id'];
$acename = $row_category['name'];
}
else if($parent_id != $root_id)
{
$hover = $db->get_sql_field("SELECT hover_title FROM " . DB_PREFIX . "categories WHERE category_id='".$ace."'","hover_title");
$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=' . $category_name . ((!empty($additional_vars)) ? ('&' . $additional_vars) : '')
. '" title="'.$row_category['hover_title'].'">' : '') . $category_name . (($show_links) ? '</a>' : '</a>')
. ' > <a href="'. $page_link . '?parent_id=' . $ace . '&name=' . $acename . ((!empty($additional_vars)) ? ('&' . $additional_vars) : '')
. '" title="'.$hover.'">' . $display_output . '</a>';
}
}
$counter++;
$root_id = $row_category['parent_id'];
}
$display_output = (($show_links && $show_category) ? '<a href="' . $page_link . '?' . $additional_vars . '"><b>Category:</b></a>' : '') . $display_output;
}
$display_output = (empty($display_output)) ? $none_msg : $display_output;
return $display_output;
}