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

图片转代码服务由CSDN问答提供 功能建议

我是WooCommerce的新手,我正在尝试使用从头开始创建的自定义主题来构建商店。 主页是一个静态页面(自定义模板),只是提供有关商店的详细信息。 我在名为woocommerce的themes文件夹中创建了一个文件夹并复制了模板文件。 所以,我想保留archive-product.php,但我需要更改基本商店页面的布局。 我希望它能够显示产品的类别和子类别以及一些没有价格的特色产品并添加到购物车中。 你建议哪种方式? 我想到了目前有效的东西,但我不知道以后是否会引起任何问题。 我编辑了archive-product.php,如下所示:

 &lt;?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)){
?&gt;  
 archive-product.php stuff 
&lt;?php} else {?&gt; 
自定义商店基本页面内容
&lt;?php}?&gt; 
   
 
 <  p>我检查网址是否以'/shop /'结尾。所以根据网址使用archive-product.php的代码。 这样可以吗? 有没有其他更安全的方法来实现这一目标?
任何帮助将不胜感激。 谢谢 
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题