我想在下面的圖片中顯示交替列中的帖子。當第一排滿了時,另一個將被製成另一個樣式。這也適用於第3,第4等。這取決於帖子的數量。WordPress替代帖子列
在這裏你可以看到我的wordpress的PHP/HTML代碼。
<?php get_header();?>
<div class="tab-content">
<div class="container-fluid no-padding">
<?php
$args = array(
'post_type' => 'case',
'category_name' => 'website',
'posts_per_page' => -1
);
$query = new WP_Query($args);
if ($query->have_posts()) :
$i = 0;
while($query->have_posts()) :
$query->the_post();
$i++;
if($i <= 5) {
if($i == 1) {
?>
<div class="big-pane col-lg-6">
<a href="<?php the_permalink(); ?>"><div style='background: url("<?php the_post_thumbnail_url();?>") no-repeat; background-size:cover; width:100%; height:100%;'></div></a>
<div class="text-box">
<h1><?php the_title(); echo" ".$i?></h1>
<p><?php the_field('sub_titel');?></p>
<a href="<?php the_permalink(); ?>">Bekijk project</a>
</div>
</div>
<div class="small-pane-holder1 col-lg-6">
<?php
}
else { ?>
<div class="small-pane col-lg-6">
<a href="<?php the_permalink(); ?>"><div style='background: url("<?php the_post_thumbnail_url();?>") no-repeat; background-size:cover; width:100%; height:100%;'></div></a>
<div class="text-box">
<h1><?php the_title(); echo" ".$i?></h1>
<p><?php the_field('sub_titel');?></p>
<a href="<?php the_permalink(); ?>">Bekijk project</a>
</div>
</div>
<?php
if($i == 5){ ?>
</div>
<div class="clearfix"></div>
<?php
}
}
}
else {
$i = 1;
if($i == 1){ ?>
<div class="big-pane col-lg-6 pull-right">
<a href="<?php the_permalink(); ?>"><div style='background: url("<?php the_post_thumbnail_url();?>") no-repeat; background-size:cover; width:100%; height:100%;'></div></a>
<div class="text-box">
<h1><?php the_title(); echo" ".$i?></h1>
<p><?php the_field('sub_titel');?></p>
<a href="<?php the_permalink(); ?>">Bekijk project</a>
</div>
</div>
<div class="small-pane-holder2 col-lg-6 ">
<?php
}
else {?>
<div class="small-pane col-lg-6">
<a href="<?php the_permalink(); ?>"><div style='background: url("<?php the_post_thumbnail_url();?>") no-repeat; background-size:cover; width:100%; height:100%;'></div></a>
<div class="text-box">
<h1><?php the_title(); echo" ".$i?></h1>
<p><?php the_field('sub_titel');?></p>
<a href="<?php the_permalink(); ?>">Bekijk project</a>
</div>
</div>
</div>
<?php ?>
<div class="clearfix"></div>
<?php
}
}
endwhile;
echo $i;
else:
echo "<p>Sorry voor de teleurstelling :(!</p>";
endif;
wp_reset_postdata(); ?>
</div>
</div>
<?php get_footer();?>
此代碼的工作原理,但不足以實現我的目標。我做了這個代碼輸出的截圖。請看下圖:
的問題是最後一排。這張大照片作爲第二排對齊右側,但其風格必須與第一排相同。
我仍然想給出一個暗示,我認爲是造成這個問題..我不能設置$i = 1
和while循環的結束。每行從1到5計數,但最後一行有問題(因爲沒有采用與第一行相同的樣式)。我把櫃檯放在標題後面。
我真的嘗試了很多..我做錯了什麼?請幫幫我。
在此先感謝
我認爲這顯然是有問題的:'$ i = 1;如果($ i == 1)...'你永遠不會執行其他代碼分支。 – miken32
是的,你知道我該如何解決這個問題嗎?我認爲我應該在一個循環內做一個循環,但我不知道該怎麼做。你可以幫我嗎? – FFB