开发者

WordPress Loopcounting

开发者 https://www.devze.com 2023-02-06 14:12 出处:网络
Having a little iss开发者_高级运维ue at the moment, I\'m trying to insert divs into a loop depending on how many posts there are.

Having a little iss开发者_高级运维ue at the moment, I'm trying to insert divs into a loop depending on how many posts there are.

So if there are only 2 posts out of a total 9 available slots I want 7 Divs with No post inside to show...

The problem I'm having is that I have this code at the moment:

<?php $nopost = '<div class="noPost">No post</div>' ?>

<?php $counter = 1; $counter++ ?>

<?php
    if($counter == 1) {
        echo str_repeat($nopost, 8);
    }
    elseif($counter == 2) {
        echo str_repeat($nopost, 7);
    } 
?>

Problem is, is that the loop will count, 1 and 2 not total of 2 so it will output 15 divs instead of what I want which is in the statement.

I'm really not sure how to go about this one Ive spent the past hour faffing around and figured I'd ask the pro's lol.

Live example of what I mean, http://thefinishedbox.com


Hard to answser without seeing the exact code, but you need to put the counter initialization outside of the loop, then put the counter incrementing and the printing of the results inside the loop. Again, hard to say without seeing the loop.

0

精彩评论

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

关注公众号