Directory browse page
Posted 01/04/2008 - 17:35 by Michelle
It's likely to be some months before I get to writing this tutorial so I decided to throw up some tidbits. These are offered as is. Please don't ask for support. I'm already behind in supporting forums & profiles and just can't add to that. Don't expect to be able to just drop this in and have it work but, if you have some idea of what you're doing, this may be helpful.
For the top level directory page, I have a vocabulary, Directory Categories, with two levels of terms. The top level is a broad category and the second level narrows it down. I used the panels_by_term view style found when you have both the views bonus pack and the panels module. This is with panels 1 as this was done before panels 2 was around. This is the export of the view, called directory_browse:
<?php
$view = new stdClass();
$view->name = 'directory_browse';
$view->description = 'Browsable directory';
$view->access = array (
);
$view->view_args_php = '// Always use 8 as the augment since that\'s the directory\'s taxonomy
if (!$args[0]) {
$args[0] = 8;
}';
$view->page = TRUE;
$view->page_title = 'Browse Directory';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'panels_threecol_term';
$view->url = 'directory/browse';
$view->use_pager = FALSE;
$view->nodes_per_page = '0';
$view->menu = TRUE;
$view->menu_title = 'Browse directory';
$view->menu_tab = TRUE;
$view->menu_tab_weight = '0';
$view->menu_tab_default = TRUE;
$view->menu_tab_default_parent = NULL;
$view->menu_tab_default_parent_type = 'normal';
$view->menu_parent_tab_weight = '1';
$view->menu_parent_title = 'Directory';
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'sticky',
'sortorder' => 'DESC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'title',
'sortorder' => 'ASC',
'options' => '',
),
);
$view->argument = array (
array (
'type' => 'vocid',
'argdefault' => '1',
'title' => '%1',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
array (
'type' => 'taxid',
'argdefault' => '6',
'title' => '%1 - %2',
'options' => '9',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;
?>Note the argument code is hardcoded with my vocab ID.
To make the page look how it does takes some heavy theming. You can put this in your template.php:
<?php
// BEGIN Override the browse directory view (panels by term) theming
function phptemplate_views_bonus_panels_byterm_summary_directory_browse($view) {
drupal_add_css(drupal_get_path('module', 'views_bonus') .'/views_bonus.css');
// argument 0 must be a vocabulary ID
$vid = $view->args[0];
// Get the taxonomy tree from the argument to the view
$tree = taxonomy_get_tree($vid);
// group terms with their parent
foreach ($tree as $term) {
$cnt = taxonomy_term_count_nodes($term->tid);
if ($term->depth == 0) {
// Top level category. Add the "all" to the URL to show all subterms when the link is clicked
$txt = array($prefix. l($term->name . " ($cnt)", "taxonomy/term/$term->tid/all"));
$parent_tid = $term->tid;
$groups[$parent_tid]['header'] = $txt;
} else {
// This bit is a pseudo tagadelic for the terms. It takes the number of nodes for a term and divides
// it by 5 and then uses just the whole number part. If a term has at least one node, it gets a 1. If
// a term has more than 25 nodes, it stays at 5. These numbers are then used to add an extra class of
// "sizedterm-N" where N is 0-5 that can be styled in CSS to make the terms look different based on
// the number of nodes in the term.
$sizeclass = floor($cnt/5);
if ($sizeclass == 0 && $cnt > 0) {
$sizeclass = 1;
}
if ($sizeclass > 5) {
$sizeclass = 5;
}
$txt = array('<span class="sizedterm-' . $sizeclass . '">' . l($term->name . " ($cnt)", "taxonomy/term/$term->tid") . '</span>');
$groups[$parent_tid]['rows'][] = $txt;
}
}
// Spread the across 2 columns
$content = array();
$i=0;
foreach ($groups as $group) {
if ($i % 2) {
$section = 'left';
} else {
$section = 'right';
}
// Create a comma separated list of subterms
$subterms = array();
foreach ($group['rows'] as $subterm) {
array_push($subterms, $subterm[0]);
}
$subterms = implode(", ", $subterms);
$content[$section] .= '<div style="display:block;"><h3>' . $group['header'][0] . "</h3>" . $subterms . "</div>";
$i++;
}
return panels_print_layout('twocol', $content);
}
// END Override the browse directory view (panels by term) theming
?>I think this is all the CSS for it but there may be more spread out in my .css file:
.view-summary-directory-browse h3 {
background: #356AA0 url(images/bluegradient-medium.jpg) repeat-x;
color: White;
padding : .25em;
margin-bottom: .25em;
}
.view-summary-directory-browse h3 a {
color: White;
}
.sizedterm-0 {
font-size: .9em;
}
.sizedterm-1 {
font-weight:bold;
font-size: 1.1em;
}
.sizedterm-2 {
font-weight:bold;
font-size: 1.2em;
}
.sizedterm-3 {
font-weight:bold;
font-size: 1.3em;
}
.sizedterm-4 {
font-weight:bold;
font-size: 1.4em;
}
.sizedterm-5 {
font-weight:bold;
font-size: 1.5em;
}
I'll try to throw more tidbits out as time permits. Hopefully that will help someone.
Michelle
Site contents are licensed under a