亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Woocommerce 產品/類別循環問題

Woocommerce 產品/類別循環問題

PHP
翻閱古今 2023-04-21 17:23:25
我安裝了最新的 Woocommerce 和最新的 Wordpress。我已經安裝了網格/列表切換。我的問題從這里開始。因為它將所有類別和產品更改為列表視圖我想要網格視圖中的類別和列表視圖中的產品。所以我搜索并發現類別和產品在 template/loop/loop-start.php 上使用相同的開始和結束循環“>可以在那里更改它,但隨后它會將所有內容更改為該類?,F在我的解決方案是向此頁面添加條件標簽但這有點問題。見代碼<?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 更改了很多代碼,所以沒有任何答案或太舊而無法使用。
查看完整描述

1 回答

?
白板的微信

TA貢獻1883條經驗 獲得超3個贊

請記住將 woocommerce/template/loop/loop-start.php 和 loop-end.php 復制到你的 theme/woocommerce/loop/loop-start.php 和 loop-end.php


循環/loop-start.php


/*This is the main cat on homepage or shop page*/

if (is_shop()|| is_front_page()) {

/*this can be any thing you want it to be <ul><div>*/

echo '<div class="yourclass">';

}?

/*this should be your sub categories 1 level down*/

else if ( is_product_category(array('cat1', 'cat2','cat3', 'cat4', 'cat5'))){

/*this can be any thing you want it to be <ul><div>*/

echo '<div class="yourclass">';

}

/*this should be your sub categories 2 level down*/

?else if ( is_product_category(array('subcat1','subcat2'))){

echo '<ul class="products" id="NORMAL">';

}

然后在loop-end.php


/*This is the main cat on homepage or shop page*/

? ? if (is_shop()|| is_front_page()) {

? ? /*this can be any thing you want it to be <ul><div>*/

? ? echo '</div>';

? ? }?

? ? /*this should be your sub categories 1 level down*/

? ? else if ( is_product_category(array('cat1', 'cat2','cat3', 'cat4', 'cat5'))){

? ? /*this can be any thing you want it to be <ul><div>*/

? ? echo '</div>';

? ? }

? ? /*this should be your sub categories 2 level down*/

? ? ?else if ( is_product_category(array('subcat1','subcat2'))){

? ? echo '</ul>';

? ? }

應該有更好的方法來做到這一點,但對我來說,這是我所能做的。


查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號