/** * 取得自定义导航栏列表 * @param string $type 位置,如top、bottom、middle * @return array 列表 */ function get_navigator($ctype = '', $catlist = array()) { $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('nav') . ' WHERE ifshow = \'1\' ORDER BY type, vieworder'; $res = $GLOBALS['db']->query($sql); $cur_url = substr(strrchr($_SERVER['REQUEST_URI'], '/'), 1); if (intval($GLOBALS['_CFG']['rewrite'])) { if (strpos($cur_url, '-')) { preg_match('/([a-z]*)-([0-9]*)/', $cur_url, $matches); $cur_url = $matches[1] . '.php?id=' . $matches[2]; } } else { $cur_url = substr(strrchr($_SERVER['REQUEST_URI'], '/'), 1); } $noindex = false; $active = 0; $navlist = array('top' => array(), 'middle' => array(), 'bottom' => array()); while ($row = $GLOBALS['db']->fetchRow($res)) { $navlist[$row['type']][] = array('name' => $row['name'], 'opennew' => $row['opennew'], 'url' => $row['url'], 'ctype' => $row['ctype'], 'cid' => $row['cid']); } /*遍历自定义是否存在currentPage*/ foreach ($navlist['middle'] as $k => $v) { $condition = empty($ctype) ? strpos($cur_url, $v['url']) === 0 : strpos($cur_url, $v['url']) === 0 && strlen($cur_url) == strlen($v['url']); if ($condition) { $navlist['middle'][$k]['active'] = 1; $noindex = true; $active += 1; } if (substr($v['url'], 0, 8) == 'category') { $cat_id = $v['cid']; $children = get_children($cat_id); $cat_list = get_categories_tree_xaphp($cat_id); $navlist['middle'][$k]['cat'] = 1; $navlist['middle'][$k]['cat_list'] = $cat_list; $navlist['middle'][$k]['goods'] = get_category_child($cat_id, '', 6); } if ($v['ctype'] == 'a') { $cat_id = $v['cid']; $navlist['middle'][$k]['cat_article'] = get_cat_articles($cat_id, 1, 6); } } if (!empty($ctype) && $active < 1) { foreach ($catlist as $key => $val) { foreach ($navlist['middle'] as $k => $v) { if (!empty($v['ctype']) && $v['ctype'] == $ctype && $v['cid'] == $val && $active < 1) { $navlist['middle'][$k]['active'] = 1; $noindex = true; $active += 1; } } } } if ($noindex == false) { $navlist['config']['index'] = 1; } return $navlist; }
$smarty->assign('hot_goods', get_category_recommend_goods('hot', $children, $brand, $price_min, $price_max, $ext)); $count = get_cagtegory_goods_count($children, $brand, $price_min, $price_max, $ext); $max_page = $count > 0 ? ceil($count / $size) : 1; if ($page > $max_page) { $page = $max_page; } $goodslist = category_get_goods($children, $brand, $price_min, $price_max, $ext, $size, $page, $sort, $order); if ($display == 'grid') { if (count($goodslist) % 2 != 0) { $goodslist[] = array(); } } $smarty->assign('goods_list', $goodslist); $smarty->assign('category', $cat_id); if ($dwt_name == 'category_top') { $child_list = get_category_child($cat_id, ' AND is_new = 1 '); $on_top_goods = get_on_top_goods($cat_id, 10); $smarty->assign('cat_child', $child_list); $smarty->assign('on_top_goods', $on_top_goods); $smarty->assign('cat_info', $cat); $smarty->assign('group_buy_goods', index_get_group_buy()); // 团购商品 } else { $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . ' WHERE cat_id = ' . $cat_id; $parent_id = $GLOBALS['db']->getOne($sql); while ($parent_id != 0) { $parent_id_org = $parent_id; $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . ' WHERE cat_id = ' . $parent_id; $parent_id = $GLOBALS['db']->getOne($sql); } $cat = get_cat_info($parent_id_org);
foreach ($goodslist as $key => $goodsvalue) { $goodslist[$key]['shop_price'] = number_format($goodsvalue['shop_price']); } if ($display == 'grid') { if (count($goodslist) % 2 != 0) { $goodslist[] = array(); } } $smarty->assign('goods_list', $goodslist); $smarty->assign('category', $cat_id); $cat['url'] = build_uri('category', array('cid' => $cat['cat_id']), $cat['cat_name']); if ($dwt_name == 'category_top') { $on_top_goods = get_on_top_goods($cat_id, 11); $smarty->assign('on_top_goods', $on_top_goods); $smarty->assign('categories_child', get_cat_child($cat_id)); $smarty->assign('cat_best_goods', get_category_child($cat_id, ' AND is_best = 1 ')); $smarty->assign('cat_info', $cat); $smarty->assign('brands1', get_brands1()); } else { $smarty->assign('cat_info', $cat); $smarty->assign('categories_left', get_categories_tree_left($cat_id)); } $smarty->assign('script_name', $dwt_name); assign_pager('category', $cat_id, $count, $size, $sort, $order, $page, '', $brand, $price_min, $price_max, $display, $filter_attr_str); // 分页 assign_dynamic($dwt_name); // 动态内容 } $smarty->display($dwt_name . '.dwt', $cache_id); /*------------------------------------------------------ */ //-- PRIVATE FUNCTION