我想使用 Php 将我的产品加载为网格
I Want To Load My Products As A Grid Using Php
我正在构建一个站点,我想在桌面设备上将所有产品加载为 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; ?>
您需要在循环外定义容器class。试试这个。
<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>
我正在构建一个站点,我想在桌面设备上将所有产品加载为 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; ?>
您需要在循环外定义容器class。试试这个。
<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>