public function header() { $where['siteid'] = get_site_id(); $res = CMS_M('web_baseinfo')->where($where)->select(); foreach ($res as $key => $val) { if ($val['info_key'] == 'title') { $title = $val['info_val']; $id = id(); $cat_id = cat_id(); if (!empty($cat_id)) { $all_parent = array(); get_single_parent($cat_id, $all_parent); krsort($all_parent); foreach ($all_parent as $single_Parent) { if ($single_Parent['title'] == '') { $title = $single_Parent['cat_name'] . ' - ' . $title; } else { $title = $single_Parent['title'] . ' - ' . $title; } } } if (!empty($cat_id) && !empty($id)) { $top_parent_id = top_parent($cat_id); $res = CMS_M('category')->where('category_id=' . $top_parent_id)->find(); $table = CMS_M('cm_table')->where('table_id=' . $res['module_id'])->find(); $table_name = $table['table_name']; $table_m = CMS_M($table_name); $table_m_pk = CMS_M($table_name)->getPk(); $art = CMS_M($table_name)->where($table_m_pk . '=' . $id)->find(); if ($art['title'] != '') { $title = $art['title'] . ' - ' . $title; } } $this->assign('seo_' . $val['info_key'], $title); } else { $this->assign('seo_' . $val['info_key'], $val['info_val']); } } }
function get_single_parent($cat_id, &$result) { $res = CMS_M('category')->where('category_id=' . $cat_id)->find(); $result[] = $res; if ($res['parent_id'] != 0) { get_single_parent($res['parent_id'], $result); } else { return; } }