<?php

if (!isset($seo[1]) || !is_numeric($seo[1])) redirect();

$tagged = $_sql->query("SELECT tagName FROM tags WHERE tagId = $seo[1]");
$entries = $_sql->query("SELECT entrySlug, entryTitle, entryPublished, entryBy FROM entries INNER JOIN tagged ON taggedEntry = entryId WHERE taggedTag = $seo[1] AND entryHidden IS NULL ORDER BY entryPublished DESC");

if (theme_component('tag'))
	include theme_component('tag');
else
{
	if ($tagged->num_rows)
	{
		$tag = $tagged->fetch_assoc();
		addTitle($tag['tagName']);
		echo "<h1>$tag[tagName]</h1>";
		if ($entries->num_rows)
		{
			echo "<ul>";
			while ($data = $entries->fetch_assoc())
				echo "<li><a href='".get_entry_link($data['entrySlug'])."'>$data[entryTitle]</a></li>";
			echo "</ul>";
		}
	}
}

unset($tag);
unset($tagged);
unset($entries);
