【发布时间】:2020-05-31 10:49:17
【问题描述】:
我安装了最新的 Woocommerce 和最新的 Wordpress。 我已经安装了网格/列表切换。 我的问题从这里开始。因为它将所有类别和产品更改为列表视图
我想要网格视图中的类别
listView 中的产品。
所以我搜索并发现类别和产品使用相同的开始和结束循环 模板/循环/循环开始.php ">
可以在那里进行更改,但随后会将所有内容更改为该类。
现在我的解决方案是向此页面添加条件标签
但这有点问题。看代码
<?php
/**
* Product Loop Start
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/loop-start.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<?php
if ( is_product_category() ) {
if ( is_shop() ) {
echo '<ul class="product-category1">';
} elseif ( is_product_category( array( 'cd', 'album' ) )) {
echo '<ul class="product-category2">';
} else {
echo '<ul class="products columns-' .esc_attr( wc_get_loop_prop( 'columns' ) );.' ">';
}
} ?>
<!--<ul class="products columns-<?php //echo esc_attr( wc_get_loop_prop( 'columns' ) ); ?>" id="HELP">-->
现在上面的代码可以工作了 if_shop 语句不起作用,但 is_product_category 就像一个魅力,而 else 语句也不起作用
有人可以为此指出正确的方向吗?几周来一直在寻找答案,但由于 Woocommerce 更改了很多代码,因此没有什么能接近或太旧而无法使用。
【问题讨论】:
标签: php wordpress woocommerce