Generalized list function
While there is already a theme_item_list function in Drupal, it always wraps the list in a div with class="item-list" which may not always be desirable. This more general theme function creates ordered, unordered, and definition lists without any extra markup around them, and you can pass in attributes for the main list element as well.
/* one place to print out a list. type = (unordered, ordered, definition) */
function theme_list($items = array(), $type = 'unordered', $attributes = array()) {
$output = '';
$tag = '';
$attr = '';
if (!is_array($items) || count($items) == 0) {
return '';
}
switch ($type) {
case 'definition':
$tag = 'dl';
case 'ordered':
$tag = 'ol';
case 'unordered':
default:
$tag = 'ul';
}
if (count($attributes) > 0) {
foreach ($attributes as $key => $val) {
$attr .= ' ' . $key . '="' . $val . '"';
}
}
$output .= '<' . $tag . $attr . '>';
foreach ($items as $item) {
if ($type != 'definition') {
$output .= '<li>' . $item . '</li>';
}
else {
if (is_array($item)) {
$dt = key($item);
$dd = $item[$dt];
$output .= '<dt>' . $dt . '</dt>';
$output .= '<dd>' . $dd. '</dd>';
}
else {
$output .= '<dd>' . $dd . '</dd>';
}
}
}
$output .= '</' . $tag . '>';
return $output;
}