2013-09-05 46 views
2

我已經構建了一個自定義的Wordpress主題,並正在使用Woo Commerce作爲購物車插件。它大部分已經集成好了(我已經在functions.php中添加了主題的鉤子,並且已經將Woo商業模板頁面複製到主題中的woocommerce子文件夾中。)但是,我試圖在循環外添加一個wrapper()產品類別頁面,並且不能爲我的生活制定出我需要編輯的內容以使其發揮作用。我需要這樣做才能通過CSS重新定位產品。我可以運用CSS來,但這是不夠具體,我Woo commerce:在循環之外編輯產品類別頁面

到目前爲止,我有:

  • 與內容product_cat.php和內容product.php試驗(但內循環兩種操作。
  • 嘗試了一些其他的模板頁面
  • 我已經添加了標籤包裝,start.php和包裝,end.php頁。這適用於其他的網頁,但在產品cateogry不顯示

我已經在網上和Wordpress網站上看過,但它沒有提供任何關於此事的幫助。 任何幫助將不勝感激!

親切的問候 尼克

回答

7

就找到了答案 - 我需要修改歸檔product.php

1

做一兩件事,在你的自定義主題的根並將其命名爲「woocommerce」創建一個文件夾。現在,您可以將WooCommerce插件中的模板複製到您的自定義主題woocommerce文件夾中,並覆蓋任何WooCommerce模板文件。你可以在plugins/woocommerce/template/找到WooCommerce模板文件

希望這會對你有所幫助。

+0

不要編輯wp-content/plugins中的模板文件。當你更新插件時,這些將被覆蓋。將文件複製並粘貼到您的主題目錄中並編輯新文件以安全地處理它。 – garvan

+1

@garvan Manish暗示你應該使用'你的自定義主題' - 我現在已經說得更清楚了。 – icc97

10

對於這樣的小改動,不需要覆蓋整個文件。嘗試首先使用WooCommerce提供的鉤子。你可以在你的主題functions.php中做到這一點。這些函數在您的首頁包裝器中輸出一個自定義包裝器。

function start_wrapper_here() { // Start wrapper 
    echo '<div class="custom-wrapper">'; 
} 

add_action( 'woocommerce_before_main_content', 'start_wrapper_here', 20 ); 


function end_wrapper_here() { // End wrapper 
    echo '</div>'; 
} 

add_action( 'woocommerce_after_main_content', 'end_wrapper_here', 20 ); 

如果你想在所有WooCommerce頁面添加獨特的包裝,你可以通過添加條件語句上面的功能做到這一點。 Visit this page on the WooCommerce site獲取更多條件標籤。

function start_wrapper_here() { // Start wrapper 

    if (is_shop()) { // Wrapper for the shop page 

     echo '<div class="shop-wrapper">'; 

    } elseif (is_product_category()) { // Wrapper for a product category page 

     echo '<div class="product-category-wrapper">'; 

    } elseif (is_product()) { // Wrapper for a single product page 

     echo '<div class="product-wrapper">'; 

    } 
} 

add_action( 'woocommerce_before_main_content', 'start_wrapper_here', 20 ); 

不要忘了再關閉它們。

function end_wrapper_here() { // End wrapper 
    if (is_shop()) { 

     echo '</div>'; 

    } elseif (is_product_category()) { 

     echo '</div>'; 

    } elseif (is_product()) { 

     echo '</div>'; 

    } 
} 

add_action( 'woocommerce_after_main_content', 'end_wrapper_here', 20 ); 

如果你wan't改變實際頁面頂部封裝(默認:<div id="container">),你應該編輯一個WooCommerce功能。此功能通常會使用get_template_part()調用wrapper-start.phpwrapper-end.php文件。我們現在重寫這個函數並且回顯我們自己的包裝器。

function woocommerce_output_content_wrapper() { // Start wrapper for all the page contents 
    echo '<div class="custom-wrapper">'; 
} 

add_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 20 ); 


function woocommerce_output_content_wrapper_end() { // End wrapper for all the page contents 
echo '</div>'; 
} 

add_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 20 ); 
相關問題