doupeng6890 2015-06-11 11:35
浏览 146
已采纳

WooCommerce - 更改商店页面布局,但保留archive-product.php

I am new to WooCommerce and I am trying to build a shop using my custom theme created from scratch. The home page is a static page (custom template) just giving details about the shop . I created a folder in my themes folder named woocommerce and copied the template files. So, I want to keep the archive-product.php but I need to change the layout of the basic shop page. I want it to show the categories and subcategories of the products and some featured products with no prices and add to cart stuff. Which way do you suggest? I thought of something which currently works but I don't know if it will cause any issues later. I edited the archive-product.php like this:

<?php 
$shop_url = "$_SERVER[REQUEST_URI]";
$shop_end = "/shop/";
function endsWith($haystack, $needle) {
    $length = strlen($needle);
    if ($length == 0) {
        return true;
    }
    return (substr($haystack, -$length) === $needle);
}
if (!endsWith($shop_url, $shop_end)) { 
?> 
    archive-product.php stuff 
<?php } else { ?>
    custom shop basic page stuff
<?php } ?>

I check if the url ends to '/shop/'...So the code of archive-product.php is used according to url. Is this ok or not? Is there any other safer way to achieve this? Any help would be appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • duan7264 2015-06-11 14:10
    关注

    Take a look at the taxonomy-product_cat.php and taxonomy-product_tag.php templates and you will see that they both call the archive-product.php template.

    wc_get_template( 'archive-product.php' );
    

    Therefore, if you wish to change the shop archive, but not the taxonomy archives you need to duplicate the archive-product.php to another file... say: archive-product-alt.php and change the taxonomy templates to call this file instead.

    wc_get_template( 'archive-product-alt.php' );
    

    Or, alternatively, you could just copy the contents of archive-product.php into taxonomy-product_cat.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口