开发者

In a PHP (Wordpress) loop how do you generate a sequence of unique numbers?

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

<?php if ( have_posts() ) while ( have_posts() ) 开发者_如何学C: 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..


<?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; ?>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜