我正在嘗試創建一個顯示特定類別卡片的模板。我已經設法得到它,但是我缺少一些東西。'card-deck' 類不斷迭代每個回圈。我怎么能說出那個類一次?我試圖放在回圈之外,但它只影響第一次迭代。
這是代碼
<?php
// the query
$the_query = new WP_Query(array(
'category_name' => 'events',
'post_status' => 'publish',
));
?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="card-deck text-center">
<div class="card">
<img
src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>"
class="card-img-top wp-post-image"
alt="<?php the_title_attribute(); ?>"
style="width:100%; height:auto;"
/>
<div class="card-body">
<h5 class="card-title"><?php the_title(); ?></h5>
<p class="card-text"><?php echo get_post_meta($post->ID, 'Event Date', true);?></p>
<p class="card-text">
<small class="text-muted"
><a
href="<?php the_permalink(); ?>"
>Show More</a
></small
>
</p>
</div>
</div>
</div>
<?php endwhile; ?>
uj5u.com熱心網友回復:
將它放在回圈之外,不要忘記最后一個</div>也要與它一起放在回圈之外。
<div class="card-deck text-center">
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="card">
<img
src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>"
class="card-img-top wp-post-image"
alt="<?php the_title_attribute(); ?>"
style="width:100%; height:auto;"
/>
<div class="card-body">
<h5 class="card-title"><?php the_title(); ?></h5>
<p class="card-text"><?php echo get_post_meta($post->ID, 'Event Date', true);?></p>
<p class="card-text">
<small class="text-muted"
><a
href="<?php the_permalink(); ?>"
>Show More</a
></small
>
</p>
</div>
</div>
<?php endwhile; ?>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/528823.html
