我正在尝试创建一个备用循环here 在stackexchange上,这对我迄今为止所取得的成就有很大帮助,但我现在陷入了困境。
目标是使新闻页看起来像这样
您可以在以下地址找到开发人员网站:http://puurluc.xact.be/nieuws/
大街区,三个小街区,然后又是一个大街区。然而,当我在一个页面上只有不到5条消息时,整个布局就会变得一团糟(见上面链接的第2页),我对此有点困惑,所以我希望在这里找到一些帮助:)
我想,如果没有足够的帖子,我可以使用if($wp\\u query-current\\u post…)将输出更改为col-md-6或col-md-12但我需要找出处理这个问题的最佳方法,这样我才不会弄乱第一页。
无论如何,索引的代码。php
<?php get_header(); ?>
<section>
<div class="container">
<div class="row">
<div class="col-md-8" id="fh5co-content">
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post();
get_template_part( \'content\', \'nieuws\' );
}
}else{ ?>
<p>
<?php _e( \'Sorry, no posts matched your criteria.\' ); ?>
</p>
<?php }
?>
</div>
<div class="col-md-3 col-md-offset-1" id="fh5co-sidebar">
<div class="fh5co-side-section fh5co-nav-links">
<h2 class="fh5co-uppercase-heading-sm">Side Links</h2>
<ul>
<li class="active"><a href="#">Design is the Creation</a></li>
<li><a href="#">Construction of an Objecton</a></li>
<li><a href="#">Architectural Blueprints</a></li>
<li><a href="#">Circuit Diagrams</a></li>
</ul>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<div class="fh5co-side-section">
<h2 class="fh5co-uppercase-heading-sm">Sweet Little <p></h2>
<p>Magnam consectetur quia illo rerum aliquam doloremque omnis assumenda quasi enim ex totam provident dignissimos numquam laudantium</p>
<p><a href="#">Go! click me</a></p>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<div class="fh5co-side-section">
<h2 class="fh5co-uppercase-heading-sm">Image Magnific Popup</h2>
<div class="fh5co-spacer fh5co-spacer-xxs"></div>
<div class="row">
<div class="col-md-12">
<p><a href="images/project_5.jpg" class="image-popup"><img src="images/project_5.jpg" alt="Image" class="img-responsive"></a></p>
</div>
<div class="col-md-6">
<p><a href="images/project_6.jpg" class="image-popup"><img src="images/project_6.jpg" alt="Image" class="img-responsive"></a></p>
</div>
<div class="col-md-6">
<a href="images/project_7.jpg" class="image-popup"><img src="images/project_7.jpg" alt="Image" class="img-responsive"></a></p>
</div>
</div>
</div>
</div>
</div>
<div class="fh5co-spacer fh5co-spacer-md"></div>
<?php
if (function_exists("wp_bs_pagination"))
{
//wp_bs_pagination($the_query->max_num_pages);
wp_bs_pagination();
}
?>
</div>
</section>
<?php get_footer(); ?>
我的新闻模板内容的代码nieuws。php
<?php
//echo $wp_query->found_posts;
//var_dump($wp_query);die();
>if( $wp_query-current_post == 0 ) : ?>
<h2><?php the_title(); ?></h2>
<div class="row">
<div class="col-md-6">
<p><?php the_excerpt(); ?></p>
</div>
<div class="col-md-6">
<p><?php the_excerpt(); ?></p>
</div>
<div class="col-md-12">
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<?php else : ?>
<?php if($wp_query->current_post == 1) : ?>
<div class="row">
<?php endif; ?>
<?php if($wp_query->current_post == 4) : ?>
<h2><?php the_title(); ?></h2>
<div class="row">
<div class="col-md-6">
<p><?php the_excerpt(); ?></p>
</div>
<div class="col-md-6">
<p><?php the_excerpt(); ?></p>
</div>
<div class="col-md-12">
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<?php else : ?>
<div class="col-md-4 col-sm-6">
<div class="fh5co-spacer-xs"></div>
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
<?php endif; ?>
<?php if($wp_query->current_post == 3) : ?>
</div>
<?php endif; ?>
<?php endif; ?>
真的希望有人能帮我解决这个问题!
最合适的回答,由SO网友:Yoeri Rousseaux 整理而成
对于那些感兴趣的人,我已经使用sizeof($wp query->posts)解决了我的问题
最终的结果就是这条内容新闻。php模板
<?php
//echo sizeof($wp_query->posts);
//var_dump($wp_query);die();
if(sizeof($wp_query->posts) == 4) : ?>
<?php if( $wp_query->current_post == 0 ) : ?>
<h3><?php the_title(); ?></h3>
<div class="row">
<div class="col-md-12">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<?php else : ?>
<?php if($wp_query->current_post == 1) : ?>
<div class="row row-eq-height">
<?php endif; ?>
<div class="col-md-4 col-sm-6">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<div class="fh5co-spacer-xs"></div>
<p class="bottom-align-text"><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
<?php if($wp_query->current_post == 3) : ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php elseif(sizeof($wp_query->posts) == 3) : ?>
<?php if( $wp_query->current_post == 0 ) : ?>
<h3><?php the_title(); ?></h3>
<div class="row">
<div class="col-md-12">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<?php else : ?>
<?php if($wp_query->current_post == 1) : ?>
<div class="row row-eq-height">
<?php endif; ?>
<div class="col-md-6 col-sm-6">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<div class="fh5co-spacer-xs"></div>
<p class="bottom-align-text"><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
<?php if($wp_query->current_post == 2) : ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php elseif(sizeof($wp_query->posts) == 1 || sizeof($wp_query->posts) == 2) : ?>
<h3><?php the_title(); ?></h3>
<div class="row">
<div class="col-md-12">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<?php else : ?>
<?php if( $wp_query->current_post == 0 ) : ?>
<h3><?php the_title(); ?></h3>
<div class="row">
<div class="col-md-12">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<?php else : ?>
<?php if($wp_query->current_post == 1) : ?>
<div class="row row-eq-height">
<?php endif; ?>
<?php if($wp_query->current_post == 4) : ?>
<h3><?php the_title(); ?></h3>
<div class="row">
<div class="col-md-12">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
</div>
<?php else : ?>
<div class="col-md-4 col-sm-6">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<div class="fh5co-spacer-xs"></div>
<p class="bottom-align-text"><a href="<?php the_permalink(); ?>" class="btn btn-primary btn-sm">Lees Meer</a></p>
</div>
<?php endif; ?>
<?php if($wp_query->current_post == 3) : ?>
</div>
<div class="fh5co-spacer fh5co-spacer-sm"></div>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>