diff --git a/bl-plugins/tags/languages/en_US.json b/bl-plugins/tags/languages/en_US.json index d6a98ca0..f9bedee0 100644 --- a/bl-plugins/tags/languages/en_US.json +++ b/bl-plugins/tags/languages/en_US.json @@ -3,5 +3,9 @@ { "name": "Tags list", "description": "Shows all tags." - } -} \ No newline at end of file + }, + "tag-sort-order": "Sort the tag list by", + "tag-sort-alphabetical": "Alphabetical order", + "tag-sort-count": "Number of times each tag has been used", + "tag-sort-date": "Date each tag was first used" +} diff --git a/bl-plugins/tags/plugin.php b/bl-plugins/tags/plugin.php index f4742cb6..892707bc 100644 --- a/bl-plugins/tags/plugin.php +++ b/bl-plugins/tags/plugin.php @@ -5,7 +5,8 @@ class pluginTags extends Plugin { public function init() { $this->dbFields = array( - 'label'=>'Tags' + 'label'=>'Tags', + 'sort'=>'date' ); } @@ -18,6 +19,19 @@ class pluginTags extends Plugin { $html .= ''; $html .= ''; + $html .= '
'; + $html .= $Language->get('tag-sort-order').': '; + $html .= '
'; + return $html; } @@ -37,16 +51,32 @@ class pluginTags extends Plugin { foreach($db as $tagKey=>$fields) { - $count = $dbTags->countPostsByTag($tagKey); - - // Print the parent - $html .= '
  • '.$fields['name'].' ('.$count.')
  • '; + $tagArray[] = array('tagKey'=>$tagKey, 'count'=>$dbTags->countPostsByTag($tagKey), 'name'=>ucfirst($fields['name'])); } + // Sort the array based on options + if ($this->getDbField('sort') == "count") + { + usort($tagArray, function($a, $b) { + return $b['count'] - $a['count']; + }); + } + elseif ($this->getDbField('sort') == "alpha") + { + usort($tagArray, function($a, $b) { + return strcmp($a['tagKey'], $b['tagKey']); + }); + } + + foreach($tagArray as $tagKey=>$fields) + { + // Print the parent + $html .= '
  • '.$fields['name'].' ('.$fields['count'].')
  • '; + } $html .= ''; $html .= ''; $html .= ''; return $html; } -} \ No newline at end of file +}