♻️ Handle categories in MenuHelper
This commit is contained in:
parent
729fc7552c
commit
b1800721f8
4 changed files with 25 additions and 26 deletions
|
@ -40,4 +40,20 @@ class Categories extends dbList {
|
|||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
public function getLinkList($hideEmpty, $showCount, $class = "", $classActive = "active")
|
||||
{
|
||||
$listLink = array();
|
||||
foreach ($this->db as $pageKey=>$pageFields) {
|
||||
$count = count($pageFields['list']);
|
||||
if (
|
||||
(!$hideEmpty || $count > 0)
|
||||
) {
|
||||
$link = DOMAIN_CATEGORIES . $pageKey;
|
||||
$name = $pageFields['name'] . ($showCount ? ' (' . $count . ')' : '');
|
||||
$listLink[] = new Link($name, $link, $class, $classActive);
|
||||
}
|
||||
}
|
||||
return $listLink;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,13 @@ class MenuHelper {
|
|||
return MenuHelper::toMenu($archives->getLinkList($monthly, $classLink, $classActive), $classUl);
|
||||
}
|
||||
|
||||
|
||||
public static function getCategories($showEmpty, $showCount, $classUl = "", $classLink = "", $classActive = "active")
|
||||
{
|
||||
global $categories;
|
||||
return MenuHelper::toMenu($categories->getLinkList($showEmpty, $showCount, $classLink, $classActive), $classUl);
|
||||
}
|
||||
|
||||
private static function toMenu($links, $classUl)
|
||||
{
|
||||
$html = '<ul '. ($classUl != '' ? 'class="'.$classUl.'"' : '') .'>';
|
||||
|
|
|
@ -44,22 +44,7 @@ class pluginCategories extends Plugin
|
|||
$html = '<div class="plugin plugin-categories">';
|
||||
$html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
|
||||
$html .= '<div class="plugin-content">';
|
||||
$html .= '<ul>';
|
||||
|
||||
// By default the database of categories are alphanumeric sorted
|
||||
foreach ($categories->db as $key => $fields) {
|
||||
$count = count($fields['list']);
|
||||
if (!$this->getValue('hideCero') || $count > 0) {
|
||||
$html .= '<li>';
|
||||
$html .= '<a href="' . DOMAIN_CATEGORIES . $key . '">';
|
||||
$html .= $fields['name'];
|
||||
$html .= ' (' . count($fields['list']) . ')';
|
||||
$html .= '</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= MenuHelper::getCategories($this->getValue('hideCero'), true);
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
|
|
|
@ -18,14 +18,5 @@
|
|||
<p><?php echo $site->description() ?></p>
|
||||
<?php endif ?>
|
||||
</hgroup>
|
||||
<nav>
|
||||
<ul>
|
||||
<?php foreach (getCategories() as $category) : ?>
|
||||
<?php if (count($category->pages())>0) : ?>
|
||||
<li><a href="<?php echo $category->permalink(); ?>"><?php echo $category->name(); ?> </a></li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
<nav><?php echo MenuHelper::getCategories(true, false); ?></nav>
|
||||
</header>
|
Loading…
Add table
Reference in a new issue