deadjournal/views/partials/tagWidget.php
2025-01-08 22:46:44 +05:00

33 lines
758 B
PHP
Executable File

<?php
use Models\TagModel;
// Instantiate the model
$tagModel = new TagModel();
// Get tags + their counts
$allTags = $tagModel->getAllTagsWithCounts();
// Output the widget
echo '<div class="widget-tags">';
echo '<h3 class="widget-title">Tags</h3>';
if (!empty($allTags)) {
echo '<ul>';
foreach ($allTags as $tag) {
$name = $tag['name'];
$count = $tag['total'];
// Link to the posts that have this tag
$url = HOME_DIRECTORY . 'index.php?url=post/tag/' . htmlspecialchars($name);
echo '<li>';
echo '<a href="' . $url . '">';
echo htmlspecialchars($name) . '</a> (' . $count . ')';
echo '</li>';
}
echo '</ul>';
} else {
echo '<p>No tags found.</p>';
}
echo '</div>';