カテゴリ/タグのリストを作ってテンプレートに渡す
# diff -wu coqoo.php.org coqoo.php
--- coqoo.php.org 2014-06-13 15:36:39.444492008 +0900
+++ coqoo.php 2014-06-13 15:24:06.209230468 +0900
@@ -124,8 +124,20 @@
}
}
-
-
+ $all_categories = array();
+ $all_tags = array();
+ foreach ($all_pages as $page) {
+ if (isset($page['category']) && !empty($page['category'])) {
+ $all_categories[] = $page['category'];
+ }
+ if (isset($page['tags']) && is_array($page['tags'])) {
+ $all_tags = array_merge($all_tags, $page['tags']);
+ }
+ }
+ $all_categories = array_unique($all_categories);
+ sort($all_categories);
+ $all_tags = array_unique($all_tags);
+ sort($all_tags);
$this->run_hooks('get_pages', array(&$pages, &$current_page, &$prev_page, &$next_page));
@@ -150,6 +162,8 @@
'current_page' => $current_page,
'next_page' => $next_page,
'is_front_page' => $url ? false : true,
+ 'all_tags' => $all_tags,
+ 'all_categories' => $all_categories,
);
$template_file = $url?'sub':'index';
navbar.html.twig
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">カテゴリ <b class="caret"></b></a>
<ul class="dropdown-menu">
{% for item in all_categories %}
<li><a href="{{ base_url }}/category/{{item}}">{{item}}</a></li>
{% endfor %}
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">タグ <b class="caret"></b></a>
<ul class="dropdown-menu">
{% for item in all_tags %}
<li><a href="{{ base_url }}/tag/{{item}}">{{item}}</a></li>
{% endfor %}
</ul>
</li>