增加只显示有效TAG的功能

This commit is contained in:
2025-05-01 16:58:17 +08:00
parent 49787b8e9c
commit a1624e5468

View File

@@ -26,6 +26,16 @@
<div class="tag-cloud"> <div class="tag-cloud">
<?php foreach ($tags as $tag): <?php foreach ($tags as $tag):
$label_theme = "default"; $label_theme = "default";
// Check if this tag has any problems associated with it
$sql = "SELECT count(*) as cnt FROM `problem` WHERE defunct='N' AND (title LIKE ? OR source LIKE ?)";
$tag_search = "%" . $tag . "%";
$result = pdo_query($sql, $tag_search, $tag_search);
if (!$result || $result[0]['cnt'] <= 0) continue; // Skip tags with no active problems
// Choose a random color theme for the tag
$hash_num = hexdec(substr(md5($tag), 0, 7));
$label_theme = $color_theme[$hash_num % count($color_theme)];
if ($label_theme == "") $label_theme = "default";
?> ?>
<a href="problemset.php?search=<?php echo urlencode($tag); ?>" class="ui <?php echo $label_theme; ?> label"><?php echo $tag; ?></a> <a href="problemset.php?search=<?php echo urlencode($tag); ?>" class="ui <?php echo $label_theme; ?> label"><?php echo $tag; ?></a>
<?php endforeach; ?> <?php endforeach; ?>