我正在尝试制作自己的版本of this 在我的尝试中,我已经实现了引导网格。我很接近,但是<div class="row">
循环导致了问题。
我只想用引导程序构建我的html结构,而不是完全依赖if
控制吐出多少存档的语句。
有没有办法添加尽可能多的<?php the_post_thumbnail(\'category-thumbnail\'); ?>
(例如)如我所愿,它会按顺序将博客吐出吗?
<?php
$count = 0;
while ( have_posts() ) : the_post();
if ( $count < 1 ) { ?>
<div class="row" style="margin-bottom:0px;">
<div class="col-md-12">
<a class="thumb" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'category-thumbnail\'); ?></a>
<div class="blog-details-wrapper clear">
<h2 class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
<span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
</div>
</div>
</div>
<?php } elseif ( $count <= 2 ) { ?>
<div class="row" style="margin-bottom:0px;">
<div class="col-md-6">
<a class="thumb" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'category-thumbnail\'); ?></a>
<div class="blog-details-wrapper clear">
<h2 class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
<span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
</div>
</div>
<div class="col-md-6">
<a class="thumb" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'category-thumbnail\'); ?></a>
<div class="blog-details-wrapper clear">
<h2 class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
<span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
</div>
</div>
</div>
<?php } $count++;
endwhile;
?>
所以在上面的代码中:我可以在每一行中调用一个或多个博客,但它将按顺序调用下一个博客。因此,在这种情况下:一个覆盖整个浏览器,然后两个50%宽度的浏览器紧挨着另一个,然后为更多的博客重复这种结构。
这可能吗?有没有一种方法可以生成一个变量或其他东西,允许您重复调用归档文件,同时按顺序吐出归档文件,而不是重复相同的归档文件?
提前谢谢。
SO网友:RLM
<?php
$counter = 1;
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php
if($counter == 1) :
?>
<div class="row clear" style="margin-bottom:0px;">
<div class="col-md-12 border-12">
<a class="thumb" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'category-thumbnail\'); ?></a>
<div class="blog-details-wrapper clear">
<h2 class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
<span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
</div>
</div>
</div>
<?php
elseif($counter == 2) :
?>
<div class="row">
<div class="col-md-6 border">
<a class="thumb-6" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'category-thumbnail\'); ?></a>
<div class="blog-details-wrapper clear">
<h2 class="">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
<span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
</div>
</div>
<?php
elseif($counter >= 2) : ?>
<div class="col-md-6 border">
<a class="thumb-6" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'category-thumbnail\'); ?></a>
<div class="blog-details-wrapper clear">
<h2 class="">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<span class="date"><?php the_time(\'F j, Y\'); ?> <?php the_time(\'g:i a\'); ?></span>
<span class="author"><?php _e( \'Published by\', \'html5blank\' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( \'Leave your thoughts\', \'html5blank\' ), __( \'1 Comment\', \'html5blank\' ), __( \'% Comments\', \'html5blank\' )); ?></span>
</div>
</div>
</div>
<?php
$counter = 0;
endif;
?>
<?php
$counter++;
endwhile;
endif;
?>