<?php
/*
Template Name: Brand Directory
*/
?>
<?php get_header(); ?>

<div id="content" class="section">

<h1 class="feed-title">Brand Directory</h1>

<div>
<p>
<?php the_content(); ?></p>
</div><!-- #entry-content -->
<?php

	$terms = get_terms('brands');

	if (count($terms)) {
		echo "<dl>";
	}
	foreach ($terms as $term) {

		$wpq = array ('taxonomy'=>'brands',
	                      'term'=>$term->slug);
		$query = new WP_Query ($wpq);
		$article_count = $query->post_count;

		echo "<dt class=\"term-heading\">";
		if ($article_count) {
			echo "<a href=\"/brands/".$term->slug."\">".$term->name."</a>";
		} else {
			echo $term->name;
		}
		echo "</dt>";
		echo "<dd class=\"term-description\">";
		echo $term->description;
		echo "<br /><br />";
		if ($article_count) {
			echo "<a class=\"taxonomy-rel-link clearfix\" href=\"/brands/".$term->slug."\">".$article_count;
		} else {
			echo "<span class=\"taxonomy-rel-link\">$article_count";
		}
		echo " related article";
		if ($article_count!= 1) echo "s"; else echo  "";
		if ($article_count>0) {
			echo " - click to view</a>";
		} else {
			echo "</span>";
		}
		echo "<br />";;
		echo "</dd>";

	}
	if (count($terms)) {
		echo "</dl>";
	}
?>

</div><!-- #content -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
