function commons_roots_item_list in Drupal Commons 6.2
File
- themes/
commons_roots/ template.php, line 225
Code
function commons_roots_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
$output = '<div class="item-list">';
if (isset($title)) {
$output .= '<h3>' . $title . '</h3>';
}
if (!empty($items)) {
$output .= "<{$type}" . drupal_attributes($attributes) . '>';
$num_items = count($items);
$c = $num_items;
foreach ($items as $i => $item) {
$c--;
$attributes = array();
$children = array();
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$data = $item;
}
if (!is_numeric($i)) {
if (count($children) > 0) {
$data .= theme_item_list($children, NULL, $type, $attributes);
// Render nested list
}
if ($c == $num_items - 1) {
$attributes['class'] = empty($attributes['class']) ? 'first' : $attributes['class'] . ' first';
}
if ($c == 0) {
$attributes['class'] = empty($attributes['class']) ? 'last' : $attributes['class'] . ' last';
}
$nth = $c % 2 ? 'even' : 'odd';
$attributes['class'] = empty($attributes['class']) ? $nth : $attributes['class'] . ' ' . $nth;
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
else {
if (count($children) > 0) {
$data .= theme_item_list($children, NULL, $type, $attributes);
// Render nested list
}
if ($i == 0) {
$attributes['class'] = empty($attributes['class']) ? 'first' : $attributes['class'] . ' first';
}
if ($i == $num_items - 1) {
$attributes['class'] = empty($attributes['class']) ? 'last' : $attributes['class'] . ' last';
}
$nth = $i % 2 ? 'even' : 'odd';
$attributes['class'] = empty($attributes['class']) ? $nth : $attributes['class'] . ' ' . $nth;
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
}
$output .= "</{$type}>";
}
$output .= '</div>';
return $output;
}