【发布时间】:2016-09-03 03:51:39
【问题描述】:
我编写了一个 php/wp 脚本,理论上应该打印一个带有类别名称、描述及其所有产品的 div。 代码如下所示:
<?php
$args2 = array( 'taxonomy' => 'product_cat', 'parent' => 9 );
$sub_cats = get_categories( $args2 );
foreach( $sub_cats as $sub_category ) { ?>
<div class="treatments-description col-md-9" id="<?php echo $sub_category->term_id;?>">
<h2 class="section-heading">
<span class="line-behind-text"><?php echo $sub_category->name;?></span>
</h2>
<p class="section-text">
OPIS: <?php echo category_description(); ?> //this part does not work too, not sure why
</p>
<h3 class="section-heading"><p class="line-behind-text">Dostępne zabiegi</p></h3>
<table class="treatments-table table products">
<tr class="table-heading">
<th class="name" id="<?php echo $sub_category->term_id;?>">Usługa</th>
<th>Czas trwania</th>
<th>Cena</th>
<th></th>
</tr> <?php
$name = $sub_category->name;
$args = array( 'post_type' => 'product',
"product_cat" => $sub_category->term_id //PROBLEM HERE
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$product = new WC_Product(get_the_ID()); ?>
<tr>
<td class="name"><?php the_title(); ?><p class="small"><?php the_content(); ?></p></td>
<td><?php the_excerpt(); ?></td>
<td><?php echo $product->price; ?>zł</td>
<td><button class="button-product materialbutton">Rezerwuj</button> </td>
</tr> <?php
endwhile;
}
else {
echo __( 'No products found' );
} ?>
<h1>THE END</h1> <?php
} //ALL UNCLOSED TAGS ARE GETTING CLOSED AFTERWARDS
现在理论上它应该像这样显示一个 div:
- a 类: 1a。类别说明 1b。类别表
- b 类: 2a。类别说明 2b。类别表
因此,正如您所看到的,它不仅没有正确布置页面(顺序为 descrption1、description2、table1、table2,注意<h1>THE END</h1> 的位置),它似乎也没有正确匹配产品类别。当 Id 放入数组时会发生相同的结果
"product_cat" => 14 //经过验证的类别id,包含帖子
我在 wp 方面经验丰富,但对 woocommerce 还是很陌生。如果有人可以帮助我解决这些问题,将不胜感激。
【问题讨论】:
-
实际上只是一点,您有很多未回答/接受的答案的未决问题?
标签: php wordpress woocommerce categories product