admin管理员组文章数量:1390519
I am new to wordpress development, I am leaning how to make a theme from scratch. I don't want to use any plugin to achieve this.
How to create first post/ fifth post/ ninth post full width, rest in three columns and so on.
I tried this but first post is not repeating
<?php get_header() ?>
<div class="container-fluid">
<div class="row">
<?php $i = 0; while ( have_posts() ) : the_post(); ?>
<?php if ($i++ == 0) : ?>
<div class="col-sm-12 blog">
<div class="row">
<div class="col-sm-8 p-0">
<?php the_post_thumbnail()?>
</div>
<div class="col-sm-4 align-self-center">
<div><h3><?php the_title()?></h3></div>
<div><?php the_excerpt()?></div>
</div>
</div>
</div>
<?php else: ?>
<div class="col-sm-4 blog py-3">
<?php the_post_thumbnail()?>
<div><h3><?php the_title()?></h3></div>
<div><?php the_excerpt()?></div>
</div>
<?php endif; ?>
<?php endwhile ?>
</div>
</div>
<?php get_footer() ?>
I am new to wordpress development, I am leaning how to make a theme from scratch. I don't want to use any plugin to achieve this.
How to create first post/ fifth post/ ninth post full width, rest in three columns and so on.
I tried this but first post is not repeating
<?php get_header() ?>
<div class="container-fluid">
<div class="row">
<?php $i = 0; while ( have_posts() ) : the_post(); ?>
<?php if ($i++ == 0) : ?>
<div class="col-sm-12 blog">
<div class="row">
<div class="col-sm-8 p-0">
<?php the_post_thumbnail()?>
</div>
<div class="col-sm-4 align-self-center">
<div><h3><?php the_title()?></h3></div>
<div><?php the_excerpt()?></div>
</div>
</div>
</div>
<?php else: ?>
<div class="col-sm-4 blog py-3">
<?php the_post_thumbnail()?>
<div><h3><?php the_title()?></h3></div>
<div><?php the_excerpt()?></div>
</div>
<?php endif; ?>
<?php endwhile ?>
</div>
</div>
<?php get_footer() ?>
Share
Improve this question
edited Mar 5, 2020 at 15:36
Ricky
asked Mar 5, 2020 at 11:59
RickyRicky
538 bronze badges
2 Answers
Reset to default 1<?php get_header() ?>
<div class="container-fluid">
<div class="row">
<?php $i = 0; while ( have_posts() ) : the_post(); ?>
<?php if ($i == 0 || $i % 4 == 0) : ?>
<div class="col-sm-12 blog">
<div class="row">
<div class="col-sm-8 p-0">
<?php the_post_thumbnail()?>
</div>
<div class="col-sm-4 align-self-center">
<div><h3><?php the_title()?></h3></div>
<div><?php the_excerpt()?></div>
</div>
</div>
</div>
<?php else: ?>
<div class="col-sm-4 blog py-3">
<?php the_post_thumbnail()?>
<div><h3><?php the_title()?></h3></div>
<div><?php the_excerpt()?></div>
</div>
<?php endif; ?>
<?php $i++; endwhile ?>
</div>
</div>
<?php get_footer() ?>
worked, changed <?php if ($i++ == 0) : ?> to <?php if ($i == 0 || $i % 4 == 0) : ?>
, can be adjusted as per the layout and number of posts.
You can try and use PHP Modulo as described here.
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php $i = 0; while ( have_posts() ) : the_post(); ?>
<?php if ($i == 0 || $i % 4 == 0) : ?>
<?php $i++; ?>
<div class="col-sm-6">
<?php the_excerpt() ?>
</div>
<?php else: ?>
<?php $i++; ?>
<div class="col-sm-12">
<?php the_excerpt() ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
本文标签:
版权声明:本文标题:theme development - How to create first post, fifth post full width, rest in three columns and so on 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744692094a2620056.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论