I have a foreach loop that I need numbered classes so I set up a counter:
<?php
$counter = 0;
?>
<?php
$html = '';
foreach ($json['feed']['entries'] as $entries){
$counter++;
$html .= '<a href="' .$entries['link']. '"><span class="feeddisplay_title">'.$entries['title']. ' </span></a>';
if($entries['publishedDate'] != '') {
$html .='<span class="feeddisplay_date">' .$entries['publishedDate']. '</span>';
}
$html .= '<p>' .$entries['contentSnippet']. '</p>';
}
?>
<div class="box feed-<?php echo $counter; ?>">
<div class="box-heading"><?php echo $heading_title; ?>:</div>
<div class="box-content">
<div class="feeddisplay"><?php echo $html ?></div>
</div>
</div>
And my output class is “feed-1” over and over. It doesn’t go up. I’ve tried a few variations and I’m stuck.
Found a solution:
Since this is opencart, this is the .tpl file and the reason the counter is not working is because there is another variable trying to do the same function on the .php controller file. I just echoed “module” instead of “counter” and it worked.