Custom Loop.php having a loop inside a loop

Need some guidance. I am creating a custom grid for a blog. So for example block 3 and 5 are bigger etc...But for this t

Need some guidance. I am creating a custom grid for a blog. So for example block 3 and 5 are bigger etc...

But for this to happen after else: i need to have two blogs in that one area so will be two in that one block.

Anyone done anything similar? who can share?

Attached is my code.

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

Need some guidance. I am creating a custom grid for a blog. So for example block 3 and 5 are bigger etc...

But for this to happen after else: i need to have two blogs in that one area so will be two in that one block.

Anyone done anything similar? who can share?

Attached is my code.

<?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; ?>
Share Improve this question asked Jan 3, 2020 at 10:22 JamesJames 34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Changes it so it works.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744863890a4597862.html

相关推荐

  • Custom Loop.php having a loop inside a loop

    Need some guidance. I am creating a custom grid for a blog. So for example block 3 and 5 are bigger etc...But for this t

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信