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