Here is the code
/blocks/block.category_jump.php
PHP Code:
function block_category_jump($params) {
global $dbConn, $site_url, $cat, $category_separator;
if (!$params['template']) {
$params['template'] = 'block.category_jump.html';
}
$tpl = new Template;
$query_filter = "";
if ($params['type'] == 'main') {
$query_filter = "and a.parent_id = '0'";
}
if ($params['type'] == 'sub') {
$query_filter = "and b.parents like '%;$cat;%'";
}
if ($params['type'] == 'all') {
$query_filter = "";
}
$query = "select a.category_id, b.path, b.path_with_url
from idx_category a
left join idx_category_path b on (a.category_id = b.category_id)
where visible = 1 $query_filter
order by b.path asc";
$result = $dbConn->Execute($query);
while ($row = $result->FetchRow()) {
preg_match_all('|<a href="(.*?)"|msi', $row['path_with_url'], $match);
$row['path_with_url'] = $site_url . '/' . $match[1][@count($match[1]) - 1];
$paths = explode($category_separator, $row['path']);
$row['path'] = str_repeat(' ', (@count($paths) - 1) * 3).$paths[@count($paths) - 1];
$categories[] = $row;
}
$tpl->assign('cat', $cat);
$tpl->assign('categories', $categories);
$tpl->display('blocks/'.$params['template'], 0);
}
/themes/kosmos/blocks/block.category_jump.html
PHP Code:
<%if $categories%>
<script language="javascript" type="text/javascript">
function category_jump(targ,selObj,restore){
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
<form action="" name="categoryjump_frm">
Category Jump :
<select name="select" onchange="category_jump('parent',this,0)">
<%section name=i loop=$categories%>
<option value="<%$categories[i].path_with_url%>" <%if $cat == $categories[i].category_id%>selected="selected"<%/if%>>
<%$categories[i].path%>
</option>
<%/section%>
</select>
</form>
<%/if%>