From 251349acaf0f8fed47aad1610b5b627a7e684f27 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 17 May 2011 17:20:06 -0700 Subject: Added category buttons and categories page --- htdocs/categories.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 htdocs/categories.php (limited to 'htdocs/categories.php') diff --git a/htdocs/categories.php b/htdocs/categories.php new file mode 100644 index 0000000..5725125 --- /dev/null +++ b/htdocs/categories.php @@ -0,0 +1,71 @@ + + * + */ + +require_once "src/base.inc.php"; + +require_once "src/header.inc.php"; + +// Do we have a path info? +if (isset($_SERVER['PATH_INFO'])) { + // Get the category + $category = addslashes(substr($_SERVER['PATH_INFO'], 1)); + + $category = Category::getByShortname($category); + if ($category) { + displayEvents($category); + + } else { + // Bad category. List them all. + listCategories(); + } + +} else { + // No category. List them all. + listCategories(); +} + + +function listCategories() { + echo "

Categories

"; + + $cats = Category::getCategories(); + foreach ($cats as $short => $name) { + $url = $GLOBALS['CONFIG']['urlroot'] . "/categories/$short"; + echo "

$name

"; + } +} + +function displayEvents($category) { + echo "

". $category->getName() ."

"; + + // Get all recent, approved posts. + $posts = new PostIterator(); + $posts->filterCategory($category->getId()); + $posts->filterStage('approved'); + $posts->query(); + + if ($posts->valid()) { + foreach ($posts as $id => $post) { + printf("

%s

" + . "
%s" + . " %s
", + + $id, $post->getName(), $post->getLocation(), $post->getAge()); + } + + } else { + echo "

No recent posts.

"; + } +} + +require_once "src/footer.inc.php"; + +?> + -- cgit v1.2.3