对于这样的小改动,不需要覆盖整个文件。尝试首先使用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