views:

19

answers:

2

If I have a list being generated in a loop, something like:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="slide">
<ul>
<li class="slide-<?php //how can I generate an integer here ?>">
<a href="#">stuff</a></li>
</ul>
</div>

How could I append a sequential number to each of those classes, and/or those hrefs?

so in that example slide-1,slide-2, etc..

A: 
<?php 
if ( have_posts() ) :
    $slideNumber = 1;
    while ( have_posts() ) : the_post(); ?>
<div id="slide">
<ul>
<li class="slide-<?php echo $slideNumber++; ?>">
<a href="#">stuff</a></li>
</ul>
</div>
<?php
    endwhile;
endif; ?>
Konstantin Leboev
Great! Thank you.
zac
A: 

I'm considering that you will put some slides in the same page. So I would put all HTML code in the PHP code. Something like that:

<?php
    while ($count <= $total) {
        echo "<div id=\"slide\">";
        echo "<ul>";
        echo "<li class=\"slide-".$count."\">";
        echo "<a href=\"#\">stuff</a></li>";
        echo "</ul>";
        echo "</div>";

        count++;
    }
?>

I didn't check the code, but it's just an idea.

Good luck.

Claudio