我正在构建一个站点,我想将所有产品加载为col-md-6
桌面设备上的网格,但我使用了下面的代码,但加载方式不同。我应该怎么办?
<?php
$params = array('posts_per_page' => 4, 'post_type' => 'product');
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<?php the_post_thumbnail(); ?>
<h5><?php the_title(); ?><br>
<form><button class="button-default" type="submit"><a href="<?php the_permalink(); ?>"> View Product Details</button></form>
</div>
<div class="col-md-6">
<?php $row ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'No Products'); ?>
</p>
<?php endif; ?>
您需要在循环外定义容器类。试试这个。
<div class="container-fluid">
<div class="row">
<?php
$params = array('posts_per_page' => 4, 'post_type' => 'product');
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>
<div class="col-md-6">
<?php the_post_thumbnail(); ?>
<h5><?php the_title(); ?><br>
<form><button class="button-default" type="submit"><a href="<?php the_permalink(); ?>"> View Product Details</button></form>
</div>
<div class="col-md-6">
<?php $row ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'No Products'); ?>
</p>
<?php endif; ?>
</div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句