2016-05-16 148 views
-2

我做了一個新的頁面模板,並將woocommerce archive-product.php複製到它中,但是在商店頁面工作時,自定義頁面沒有,有沒有辦法使它的功能與商店相同頁?注意到它也不會從視覺作曲家或普通內容中吸取任何其他內容。woocommerce頁面模板

回答

0

對於那些想要自定義woocommerce商店模板(檔案產品)的人來說,這裏是一個示例模板,它可以在任何程度上進行自定義。

<?php 

if (! defined('ABSPATH')) { 
    exit; // Exit if accessed directly 
} 

get_header('shop'); ?> 

<?php 
/** 
* woocommerce_before_main_content hook 
* 
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content) 
* @hooked woocommerce_breadcrumb - 20 
*/ 
do_action('woocommerce_before_main_content'); ?> 

<?php if (apply_filters('woocommerce_show_page_title', true)) : ?> 

    <h1 class="page-title"><?php woocommerce_page_title(); ?></h1> 

<?php endif; ?> 

<?php do_action('woocommerce_archive_description'); ?> 

<?php 

global $post, $product; 

$args = array( 
    'post_type'=>'product', 
    'posts_per_page'=>-1, 
    'orderby'=>'date', 
    'order'=>'ASC'  
); 
// get all the posts (here it would be all the wc products) 
$posts = get_posts($args); 

/** 
* woocommerce_before_shop_loop hook 
* 
* @hooked woocommerce_result_count - 20 
* @hooked woocommerce_catalog_ordering - 30 
*/ 
do_action('woocommerce_before_shop_loop'); 

if(count($posts) > 0) { 

    woocommerce_product_loop_start(); 

    woocommerce_product_subcategories(); 

    foreach($posts as $post) { 
     // this will put the current post into the GLOBAL $post object 
     setup_postdata($post); 
     // this will put the product data into GLOBAL $product object 
     wc_setup_product_data($post); ?> 

     <!-- Now you have valid WP loop, put the content-product template here --> 
     <?php wc_get_template_part('content', 'product'); ?> 

     <?php 
    } 

    woocommerce_product_loop_end(); 

} else { 
    wc_get_template('loop/no-products-found.php'); 
} 

/** 
* woocommerce_after_shop_loop hook 
* 
* @hooked woocommerce_pagination - 10 
*/ 
do_action('woocommerce_after_shop_loop'); 

/** 
* woocommerce_sidebar hook 
* 
* @hooked woocommerce_get_sidebar - 10 
*/ 
do_action('woocommerce_sidebar'); 

get_footer('shop'); ?> 
+0

謝謝這真的很有用。但隨着它的一個問題,產品加載正常,但任何頁面內容不加載,例如,我沒有加載在該頁面上的視覺作曲家幾個組件。我是否需要一個wp循環來使這些出現? –

+0

是的,這是可能的,把'the_content();'get_footer('shop');' – Sark

+0

謝謝,你的救星。 –