在循环中重复行 [英] Repeating the rows within Loop

查看:57
本文介绍了在循环中重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理WordPress帖子循环,重复相同的行.我取得了第一行,但第二行没有循环,而第一行却完美地循环了.

I'm working on a WordPress posts loop with same rows repeating. I achieved the first row but the 2nd row isn't looping whereas the first row loops perfectly.

下面是循环和屏幕截图的代码.

Below is the code for the loop and the screenshot.

循环代码

$count = 1;

$featured_posts = new \WP_Query( $args );
if ( $featured_posts->have_posts() ) : while ($featured_posts->have_posts()) : $featured_posts->the_post();
    if ( 1 == $count % 5 ) {
        echo '<div class="wh-tiles-posts-left">';
    } elseif ( 2 == $count % 5 ) {
        echo '<div class="wh-tiles-posts-right">';
    } elseif ( 4 == $count % 9 ) {
        echo '<div class="wh-tiles-posts-left2">';
    } elseif ( 5 == $count % 10 ) {
        echo '<div class="wh-tiles-posts-right2">';
    }
    $this->render_post_body( $count );

    if ( 1 == $count % 5  ) {
        echo '</div>';
    } elseif ( 3 == $count % 6 ) {
        echo '</div>';
    } elseif( 4 == $count % 9 ) {
        echo '</div>';
    } elseif ( 5 == $count % 10 ) {
        echo '</div>';
    }
    $count++;

    endwhile;
    endif;
    wp_reset_postdata();

我在做什么错?下面的图像2中显示了带有类名的div输出,以进行更好的解释.

What am I doing wrong?. The div with class names output shown in the image 2 below for better explanation.

推荐答案

我认为这与您何时添加各种div标签的计算有关,我更改了计算,尤其是仅进行了1次严格测试.

I think it's to do with your calculations as to when to add the various div tags, I've changed the calculations, especially only having 1 close test...

if ( 0 == ($count-1) % 5 ) {
    echo '<div class="wh-tiles-posts-left">';
} elseif ( 1 == ($count-1) % 5 ) {
    echo '<div class="wh-tiles-posts-right">';
} elseif ( 3 == ($count-1) % 5 ) {
    echo '<div class="wh-tiles-posts-left2">';
} elseif ( 4 == ($count-1) % 5 ) {
    echo '<div class="wh-tiles-posts-right2">';
}
$this->render_post_body( $count );

if ( 1 != ($count-1) % 5 ) {
    echo '</div>';
} 

这篇关于在循环中重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆