Skip to content

Commit

Permalink
Added dataset counts and listing of the full department list to sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Barnes committed Jul 19, 2009
1 parent cf8eb4f commit 602d205
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions themes/open-data-theme/category-25.php
Expand Up @@ -30,16 +30,34 @@
<p>Click through to see what datasets we have listed for each entity.</p>
<?php foreach ($cats as $cat_id => $title) : ?>
<?php
$departments = $wpdb->get_results("select p.post_title, p.ID " .
"from " . $wpdb->prefix . "posts as p, " . $wpdb->prefix . "term_relationships as ts " .
"where p.ID = ts.object_id " .
"and ts.term_taxonomy_id = " . $cat_id .
" order by p.post_title ASC;", ARRAY_A); ?>
$sql = "select p.ID, p.post_title, sd.department, tr.term_taxonomy_id, ds_count.num_sets" .
" from (wp_posts as p," .
" wp_supple_dataset as sd," .
" wp_term_relationships as tr)" .
" left outer join " .
" (select sd.department, count(sd.department) as num_sets" .
" from wp_posts as p, " .
" wp_supple_dataset as sd," .
" wp_term_relationships as tr" .
" where p.ID = sd.post_id" .
" and p.ID = tr.object_id" .
" and tr.term_taxonomy_id = 3" .
" group by sd.department) as ds_count " .
" on sd.department = ds_count.department " .
" where p.ID = sd.post_id" .
" and p.ID = tr.object_id" .
" and tr.term_taxonomy_id = " . $cat_id .
" order by p.post_title ASC;";

$departments = $wpdb->get_results($sql, ARRAY_A); ?>
<?php if($departments) : ?>
<h2 class="department"><?php echo $title ?></h2>
<ul>
<?php foreach($departments as $department) : ?>
<li><a href="<?php echo get_permalink($department[ID]) ?>"><?php echo $department[post_title]; ?></a></li>
<li>
<a href="<?php echo get_permalink($department[ID]) ?>"><?php echo $department[post_title]; ?></a>
<?php if ($department[num_sets]) { echo '(' . $department[num_sets] . ' datasets)'; }; ?>
</li>
<?php endforeach;?>
</ul>
<? endif ?>
Expand Down

0 comments on commit 602d205

Please sign in to comment.