views:

134

answers:

1

My PHP and programming knowledge is extremely basic, so this is probably a dumb question:

I am theming a View in Drupal 6, and I want to add an id with a consecutive number to each item in the view (first item would have the id #item1, the second #item2, etc).

I am customizing the style output (views-view-unformatted--MYVIEWNAME.tpl.php) and the row style output (views-view-fields--MYVIEWNAME.tpl.php), and I want to add a counter variable in the foreach loop in the style output tpl, and then use that variable in the row style output tpl, but the last one is not recognizing the variable. It does not give me any errors, but doesnt print the number.

I understand this has probably something to do with variables visibility, how can I declare the counter variable in the style .tpl so I can the use it in the row style .tpl?

Thank you

+1  A: 

Using a row based tpl,

$count = 0;

Then in your for/while loop looping results to print rows, something like:

<div id="row-<?php print $count;?>">
...code...
$count++;

That should do the trick, be sure to increment $count at the very end. I'm not sure if that will hold up on paged queries, though.

Kevin