Блог в меню

This commit is contained in:
Konstantin
2026-05-30 09:35:28 +03:00
parent de0344d218
commit 51109b7a3c
+22 -36
View File
@@ -24,43 +24,29 @@ class ControllerBlogMenu extends Controller {
$this->load->model('blog/article'); $this->load->model('blog/article');
$data['categories'] = array(); $data['categories'] = $this->getCategories();
$categories = $this->model_blog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_blog_category->getCategories($category['blog_category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_blog_category_id' => $child['blog_category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('configblog_article_count') ? ' (' . $this->model_blog_article->getTotalArticles($filter_data) . ')' : ''),
'href' => $this->url->link('blog/category', 'blog_category_id=' . $category['blog_category_id'] . '_' . $child['blog_category_id'])
);
}
// Level 1
$filter_data = array(
'filter_blog_category_id' => $category['blog_category_id']
);
$data['categories'][] = array(
'name' => $category['name'] . ($this->config->get('configblog_article_count') ? ' (' . $this->model_blog_article->getTotalArticles($filter_data) . ')' : ''),
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('blog/category', 'blog_category_id=' . $category['blog_category_id'])
);
}
}
return $this->load->view('blog/menu', $data); return $this->load->view('blog/menu', $data);
} }
private function getCategories($parent_id = 0, $path = '') {
$category_data = array();
$categories = $this->model_blog_category->getCategories($parent_id);
foreach ($categories as $category) {
$category_path = $path ? $path . '_' . $category['blog_category_id'] : $category['blog_category_id'];
$filter_data = array(
'filter_blog_category_id' => $category['blog_category_id']
);
$category_data[] = array(
'name' => $category['name'] . ($this->config->get('configblog_article_count') ? ' (' . $this->model_blog_article->getTotalArticles($filter_data) . ')' : ''),
'href' => $this->url->link('blog/category', 'blog_category_id=' . $category_path)
);
$category_data = array_merge($category_data, $this->getCategories($category['blog_category_id'], $category_path));
}
return $category_data;
}
} }