Search code examples
drupalvariablesdrupal-6cck

Drupal 6: pre-defined variable for amount [count] of custom type items


I'm a drupal newbie...

I researched but couldnot find :/ is there any predefined variable that gives my CCK field value count?

for example; I have field_logo_sponsor and I need to display all logo items. Now I have 5 item

<?php print $node->field_logo_sponsor[0]['view'] ?>
<?php print $node->field_logo_sponsor[1]['view'] ?>
<?php print $node->field_logo_sponsor[2]['view'] ?>
<?php print $node->field_logo_sponsor[3]['view'] ?>
<?php print $node->field_logo_sponsor[4]['view'] ?>

it is stupid to use it that way :/ if there is any count variable for that, I will just create a loop for that and display them in a for or while loop

Appreciate helps! thanks a lot!


Solution

  • How about:

    <?php
    foreach($node->field_logo_sponsor as $logo_sponsor) {
      print $logo_sponsor['view'];
    }
    ?>
    

    Also count($node->field_logo_sponsor) should return you the number of items.