對於這樣的小改動,不需要覆蓋整個文件。嘗試首先使用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.php
和wrapper-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 );
來源
2014-07-21 22:14:02
Tim
不要編輯wp-content/plugins中的模板文件。當你更新插件時,這些將被覆蓋。將文件複製並粘貼到您的主題目錄中並編輯新文件以安全地處理它。 – garvan
@garvan Manish暗示你應該使用'你的自定義主題' - 我現在已經說得更清楚了。 – icc97