在循环内具有循环的自定义Loop.php

时间:2020-01-03 作者:James

需要一些指导。我正在为博客创建一个自定义网格。例如,区块3和5更大,等等。。。

但为了让这件事发生在其他事情之后:我需要在一个区域有两个博客,所以在那个街区会有两个。

有人做过类似的事情吗?谁可以分享?

附件是我的代码。

<?php while ( have_posts() ) : the_post(); ?>

            <?php if ($wp_query->current_post  == 2): ?>

                <div class="col5x2">
                    <?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); ?>
                    <div class="col s12 m7 l7" style="background-image: url(<?php echo $thumbnail[0]; ?>);">
                    </div>
                    <div class="col s12 m5 l5">
                        <div class="text">
                            <h1><?php the_title(); ?></h1>
                            <?php the_excerpt(); ?>

                            <p><a href="<?php the_permalink(); ?>" class="btn">read more top</a></p>
                        </div>
                    </div>
                </div>


            <?php else: ?>

                <div class="col5">


                    <div class="item">
                        <div class="date">
                            Date: <?php echo get_the_date(\'jS F Y\');?>
                        </div>
                        <div class="image">
                            <?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); ?>
                            <img src="<?php echo $thumbnail[0]; ?>">
                        </div>
                        <div class="text">

                            <h2><?php the_title(); ?></h2>
                            <?php the_excerpt(); ?>
                            <p><a href="<?php the_permalink(); ?>" class="btn">read more 1</a></p>
                        </div>
                    </div>

                    <div class="item">
                        <div class="date">
                            Date: <?php echo get_the_date(\'jS F Y\');?>
                        </div>
                        <div class="image">
                            <?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); ?>
                            <img src="<?php echo $thumbnail[0]; ?>">
                        </div>
                        <div class="text">

                            <h2><?php the_title(); ?></h2>
                            <?php the_excerpt(); ?>
                            <p><a href="<?php the_permalink(); ?>" class="btn">read more 1</a></p>
                        </div>
                    </div>



                </div>

            <?php endif ?>

            <?php comments_template( \'\', true ); ?>

        <?php endwhile; ?>

1 个回复
最合适的回答,由SO网友:James 整理而成

更改它以使其工作。

<?php 

        $i = 1;
        $icount = 1;

        ?>


        <?php while ( have_posts() ) : the_post();

            if ($icount < 11) {


                if ($i % 5 == 0) {


                    echo \'<div class="col5x2">\';

                    include \'modules/projects/small-square.php\'; 

                    echo \'</div>\';

                    $i = 1;
                    $icount++;

                    continue;
                }

                if($i % 2 == 1):

                    echo \'<div class="col5">\'; 

                    endif;

                    include \'modules/projects/small-square.php\'; 
                    echo $icount;

                    if($i % 2 == 0):

                    echo \'</div>\';

                endif;

                $i++; $icount++;

            } else{



                if ($icount == 21) {


                    echo \'<div class="col5x2">\';

                    include \'modules/projects/small-square.php\'; 

                    echo \'</div>\';

                    $i = 1;
                    $icount = 1;

                    continue;
                }

                if($i % 2 == 1):

                    echo \'<div class="col5">\'; 

                    endif;

                    include \'modules/projects/small-square.php\'; 
                    echo $icount;

                    if($i % 2 == 0):

                    echo \'</div>\';

                endif;

                $i++; $icount++;


            }


            ?>




            <?php comments_template( \'\', true ); ?>

        <?php endwhile; ?>