I am using the latest Wordpress with the Storefront Theme & Child Theme.
我正在使用最新的WordPress与店面主题和儿童主题。
I am wanting to change the height:
and padding:
of the columns for WooCommerce's products (actually categories but they use the same columns).
On the shop page only the categories are displayed which do not require to be as tall as product columns (no price, no sale tag, no buy now or add to cart button etc are on categories)
我想更改WooCommerce的产品栏的高度:和填充:(实际上是分类,但它们使用相同的栏)。在商店页面上只显示不需要和产品栏一样高的类别(没有价格、没有销售标签、没有立即购买或添加到购物车按钮等都是类别)
I am using this small piece of PHP in my Child Theme Functions to try and implement this but it doesn't seem to change anything, nor are any errors given:
我在My Child主题函数中使用了这一小段PHP来尝试和实现它,但它似乎没有改变任何事情,也没有给出任何错误:
function dayles_custom_shop_columns()
{
if (function_exists('is_shop') && is_shop()) {
echo "<style type='text/css'>.storefront-full-width-content .site-main ul.products.columns-4 li.product, ul.products li.product {height:320px!important;padding:20px!important;min-height:320px!important;max-height:320px!important;}</style>";
} else {
//Do nothing.
}
}
I have also tried this using !important to see if it had any difference. But nope.
我也试过使用!重要的是看看它是否有什么不同。但不是的。
Any help is appreciated!
如有任何帮助,我们不胜感激!
更多回答
Where do you use this code? Is it inside action hook?
您在哪里使用此代码?是在动感勾手里面吗?
Hi, sorry for the confusion, I have updated the code in the question to show the full function to which I am using in my Child Theme Functions.
嗨,很抱歉造成混乱,我已经更新了问题中的代码,以显示我在我的孩子主题函数中使用的完整函数。
优秀答案推荐
You need to add a wp_head action hook in your functions:
您需要在函数中添加wp_head操作挂钩:
Example:
示例:
function my_custom_css() {
if (function_exists('is_shop') && is_shop()) {
echo "<style type='text/css'>.storefront-full-width-content .site-main ul.products.columns-4 li.product, ul.products li.product {height:320px!important;padding:20px!important;min-height:320px!important;max-height:320px!important;}</style>";
}
}
add_action('wp_head', 'my_custom_css' );
More information on wp_head action here
.
有关wp_head操作的更多信息,请单击此处。
To make the product loop on shop page of same height, please wrap all the loop items in your custom div and then write your style.
要使产品在相同高度的商店页面上循环,请将所有循环项包装在您的自定义div中,然后写下您的样式。
Paste the below code in current active theme functions.php file
将下面的代码粘贴到当前活动的主题functions.php文件中
function start_before_shop_loop_item() {
echo '<div class="custom_shop_loop_wrap">';
}
function end_after_shop_loop_item() {
echo '</div>';
}
add_action( 'woocommerce_before_shop_loop_item', 'start_before_shop_loop_item', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'end_after_shop_loop_item', 10 );
Then using the class custom_shop_loop_wrap
add your styling.
然后使用类CUSTOM_SHOP_LOOP_WRAP添加您的样式。
function custom_css_add_wrap(){?>
<style>
.custom_shop_loop_wrap{
height:height:320px;
max-height:320px;
}
</style>
<?php }
add_action('wp_head', 'custom_css_add_wrap' );
更多回答
Ahh yes of course! - Slaps forehead! Thanks for point this out. I missed my add_action.
啊,是的,当然!-拍拍额头!谢谢你指出这一点。我错过了我的附加动作。
Coming back to this, it works perfectly, but I also noticed that if people use the search box on the page this also effects the columns. Any ideas why this would be?
回到这里,它工作得很完美,但我也注意到,如果人们使用页面上的搜索框,这也会影响列。你知道为什么会这样吗?
Try to remove this from added CSS: ul.products li.product
尝试从添加的css:ul.Products li.product中删除它
我是一名优秀的程序员,十分优秀!