<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 7,
'paged' => $paged);
$wp_query = new WP_Query($args);
$count = 0;
while (have_posts()) : the_post(); ?>
<?php echo get_the_title(); ?>
<?php
$count++;
if ($count === 1) { ?>
<div class="column small-12 margin-bottom-small">
<div class="panel-brown">
<img src="" alt="" />
<h5 class="heading-white"><a href="#"><?php echo get_the_title(); ?></a></h5>
<div class="para-white">
<?php $content = get_the_content(); echo mb_strimwidth($content, 0, 200, '...');?>
</div>
</div>
</div>
<?php }
while ($count <= 2) {
$count++ ?>
<div class="column small-12 medium-6 margin-bottom-small">
<div class="panel-tan">
<h5 class="heading-white"><a href="#"><?php echo get_the_title(); ?></a></h5>
<div>
<?php $content = get_the_content(); echo mb_strimwidth($content, 0, 200, '...');?>
</div>
</div>
</div>
<?php }
while ($count <= 4) {
$count++ ?>
<div class="column small-12 medium-6 margin-bottom-small">
<div class="panel-tan">
<h5 class="heading-white"><a href="#"><?php echo get_the_title(); ?></a></h5>
<div>
<?php $content = get_the_content(); echo mb_strimwidth($content, 0, 200, '...');?>
</div>
</div>
</div>
<?php }
?>
<?php endwhile; ?>
<!-- Pagination links -->
<?php next_posts_link('← Older posts', $wp_query ->max_num_pages); ?>
<?php previous_posts_link('Newer posts →'); ?>
我挣扎理解为什么if和while语句循环相同的职位,但直接在此行之后:PHP - 同一职位而非显示接下来的文章中
while (have_posts()) : the_post();
我在哪里回应标题,而是显示帖子列表。
我想在这里实现的是为循环中输出的每个帖子创建不同的html布局。
干杯
你的意思是有第一个语句'如果$计数=== 1'但后来有'而$计数> = 2'?似乎这些都应该是如果陈述。我也看不出你是如何在主循环中使用WP_Query的结果......可能是手头的问题 – Chizzle