Easy, but I can not find the answer.
I want to list the subcategories for creating tabs in the code below. This works well on my way out. But the first tab requires <li class= "selected" > to display the content on the page load.
How to get the first echo result to include the class in the <li> element?
.
.
.
[Output]
Actual: .......... Category 1 | Category 2 | Category 3
Requires: .......... Category 1 * | Category 2 | Category 3
* class = "selected"
<ul class="cd-tabs-navigation"> <?php $argumentos = array( 'hide_empty' => 1, 'child_of' => 44, ); $categories = get_categories($argumentos); foreach($categories as $category) { echo '<li><a data-content="' . $category->slug . '" href="#' . $category->slug . '">' . $category->name . '</a></li>'; } ?> </ul>
.
.
[EDIT]
Solution by Lal. Thanks everyone!
foreach($categories as $category) { if(++$i==1) echo '<li class="selected"><a class="selected" data-content="' . $category->slug . '" href="#' . $category->slug . '">' . $category->name . '</a></li>'; else echo '<li><a data-content="' . $category->slug . '" href="#' . $category->slug . '">' . $category->name . '</a></li>'; }
source share