Skip to content

Commit

Permalink
Pass active category
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Aug 11, 2012
1 parent 7ab8b13 commit 57ce032
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion category.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
$products = query("SELECT id, name, about, price FROM products WHERE categories_id = %d AND visible = 1", $row["id"]);

htmlHead($row["name"]);
htmlHead($row["name"], $row["url"]);
foreach ($products as $product) {
echo "<h3>" . h($product["name"]) . "</h3>\n";
echo "<p>" . h($product["about"]) . "</p>\n";
Expand Down
10 changes: 5 additions & 5 deletions html.inc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

function htmlHead($title) {
function htmlHead($title, $active_url = "") {
$categories = array();
foreach (query("SELECT * FROM categories") as $row) {
$categories[$row["category_id"]][] = $row;
Expand Down Expand Up @@ -35,18 +35,18 @@ function htmlHead($title) {
<h1><?=h($title)?></h1>

<?php
printCategories($categories);
printCategories($categories, $active_url);
}

function printCategories($categories, $key = "") {
function printCategories($categories, $active_url, $key = "") {
if (!isset($categories[$key])) {
return;
}
echo "<ul>\n";
foreach ($categories[$key] as $row) {
$attrs = ($_GET["url"] == $row["url"] ? " class='active-category'" : "");
$attrs = ($active_url == $row["url"] ? " class='active-category'" : "");
echo "<li><a href='" . href("cat/$row[url]/") . "'$attrs>" . h($row["name"]) . "</a>\n";
printCategories($categories, $row["id"]);
printCategories($categories, $active_url, $row["id"]);
}
echo "</ul>\n";
}

0 comments on commit 57ce032

Please sign in to comment.