By diovi on
I've created a view and themed it, but I would like to give each <li> tag its own id <li id="something">
I know how to give the <ul> tag a custom id, but I don't know how to do it for the <li> tag
This is the original views code:
return theme('item_list', $items);
Changing <ul> to <ol>:
return theme('item_list', $items, NULL, 'ol');
Giving <ul> custom id:
return theme('item_list', $items, NULL, 'ul id="chooserul"');
So my question is: How would I change the <li> tag for the view so that each <li> had a unique id that I could define using an incrementing count? I know just enough php to get myself in trouble, but I'm familiar with other programming code so I understand the concepts well enough.
Here is my full template.php views function
/**
* views template to output a view.
* This code was generated by the views theming wizard
* Date: Mon, 07/07/2008 - 20:33
* View: bios
*
* This function goes in your template.php file
*/
function phptemplate_views_view_list_bios($view, $nodes, $type) {
$fields = _views_get_fields();
$taken = array();
// Set up the fields in nicely named chunks.
foreach ($view->field as $id => $field) {
$field_name = $field['field'];
if (isset($taken[$field_name])) {
$field_name = $field['queryname'];
}
$taken[$field_name] = true;
$field_names[$id] = $field_name;
}
// Set up some variables that won't change.
$base_vars = array(
'view' => $view,
'view_type' => $type,
);
foreach ($nodes as $i => $node) {
$vars = $base_vars;
$vars['node'] = $node;
$vars['count'] = $i;
$vars['stripe'] = $i % 2 ? 'even' : 'odd';
foreach ($view->field as $id => $field) {
$name = $field_names[$id];
$vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
if (isset($field['label'])) {
$vars[$name . '_label'] = $field['label'];
}
}
$items[] = _phptemplate_callback('views-list-bios', $vars);
}
if ($items) {
return theme('item_list', $items);
}
}
Comments
theme_item_list
Giving
<ul>custom id:return theme('item_list', $items, NULL, 'ul', array('id' => 'chooserul'));You can refer to http://api.drupal.org/api/function/theme_item_list/5.
To add an id to each item, use a line like this;-
$items[] = array('data' => _phptemplate_callback('views-list-bios', $vars), 'id' => 'item-' . $i);___________________
It’s in the detaιls…
demonstration portfolio
subscribing
subscribing
Sustainable Transport in Drupal.
www.ridebubble.org
www.nosfuimos.cl