Inserting a sequential class in the loop
-
I want to add a unique and incremental number as the class of
<li>tags in a list. This is so that I can style the li according to it’s position regardless of what the content is. eg:<ul> <?php global $post; $myposts = get_posts('category=1&numberposts=3&order=des'); foreach($myposts as $post) : setup_postdata($post);?> <li class="<?php INSERT_A_NUMBER_HERE_IN_ORDER ?>"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li> <?php endforeach; ?> </ul>So the output will look like:
<ul> <li class="1">Title here</li> <li class="2">Title here</li> <li class="3">Title here</li> </ul>I’m sure that it’s not difficult, but not something I have come across.
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Inserting a sequential class in the loop’ is closed to new replies.