如何编写此Wordpress短代码?
早上好 我想问一个为WordPress-WooCommerce网站生成目录列表的方法。 目录页面是WooCommerce结构的补充,旨在为习惯于旧纸质目录的客户提供仿效 我做了一个模板,从产品目录中抽出一个列表。见所附代码如何编写此Wordpress短代码?,wordpress,woocommerce,shortcode,Wordpress,Woocommerce,Shortcode,早上好 我想问一个为WordPress-WooCommerce网站生成目录列表的方法。 目录页面是WooCommerce结构的补充,旨在为习惯于旧纸质目录的客户提供仿效 我做了一个模板,从产品目录中抽出一个列表。见所附代码 <?php /* Template Name: Wiz_Catalogue */ ?> <?php get_header(); ?> <?php // the query $args = array( 'post_type'
<?php /* Template Name: Wiz_Catalogue */ ?>
<?php get_header(); ?>
<?php
// the query
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => '100',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => 397,
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
)
),
'orderby' => 'title',
'order' => 'ASC',
);
$wpb_all_query = new WP_Query($args);
?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<h3> Select link to view and order, use browser back button to return to catalogue</h3>
<?php $i = 0; ?>
<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) :
$wpb_all_query->the_post();
$sku = get_post_meta( get_the_ID(), '_sku', true );
if (strpos($sku, '_') > 0 ) { $sku = substr($sku, strpos($sku, '_')+1);} /* remove _ */
$price = get_post_meta( get_the_ID(), '_price', true );
$product = wc_get_product( get_the_ID() ); /* get the WC_Product Object */
$productAttribute = $product->get_attribute( 'pa_1_scale' ); /* get scale using slug */
?>
<?php if ($i == 0): ?>
<table class = "wizcat">
<thead>
<tr>
<th>SKU</th>
<th>Title </th>
<th>Scale </th>
<th>Price</th>
<th>Link </th>
</tr>
</thead>
<tbody>
<?php endif; ?>
<?php $i++; ?>
<tr>
<td><?php echo $sku;?></td>
<td><?php the_title(); ?></td>
<td><?php echo $productAttribute ; ?></td>
<td><?php echo wc_price( wc_get_price_including_tax( $product ) );?></td>
<td><a href="<?php the_permalink(); ?>">View</td>
</tr>
<?php if ($i == 25):?>
<?php $i = 0; ?>
</table>
<?php endif; ?>
<?php endwhile; ?>
<!-- end of the loop -->
</tbody>
</table>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php
/*do_action( 'storefront_sidebar' ); */
get_footer();
选择要查看和订购的链接,使用浏览器上一步按钮返回目录
SKU
标题
规模
价格
链接
如果它适合你的需要,它可能是一个很好的方法。请参阅短代码文档: