admin管理员组文章数量:1388067
i want show category description on my archive product page
i add this code to my template:
<?php if ( category_description() ) ?>
<div class="myproductdescription"><?php echo category_description(); ?></div>
and add this css code to style.css:
.myproductdescription{
position: relative;
background-color: #fff;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
border-radius: 7px;
box-shadow: 0 2px 2px 0 rgba(168, 172, 185, .3);
padding: 15px;
margin-bottom: 20px;
line-height: 25px;}
its work! but show box shadow and padding in archive product page is`t description!
I want not show if category not description
i want show category description on my archive product page
i add this code to my template:
<?php if ( category_description() ) ?>
<div class="myproductdescription"><?php echo category_description(); ?></div>
and add this css code to style.css:
.myproductdescription{
position: relative;
background-color: #fff;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
border-radius: 7px;
box-shadow: 0 2px 2px 0 rgba(168, 172, 185, .3);
padding: 15px;
margin-bottom: 20px;
line-height: 25px;}
its work! but show box shadow and padding in archive product page is`t description!
I want not show if category not description
Share Improve this question asked Apr 28, 2020 at 23:10 mostafamostafa 32 bronze badges1 Answer
Reset to default 0You're not opening and closing the if
statement correctly, so the div is always being output. While you can use if
statements without the opening and closing parts like this if there's only one line of code, that doesn't work if the PHP tags are closed for HTML.
So you need to have this:
<?php if ( category_description() ) : ?>
<div class="myproductdescription"><?php echo category_description(); ?></div>
<?php endif; ?>
Or
<?php if ( category_description() ) { ?>
<div class="myproductdescription"><?php echo category_description(); ?></div>
<?php } ?>
I prefer the more verbose style when mixed in with HTML, but either one is fine.
Generally you should always avoid using the if
statement without opening and closing brackets, even if you've only got one line of code in the condition. It makes your code less clear and can cause serious issues if code that is supposed to be in the condition is added on a new line without adding the brackets. A major vulnerability in iOS was caused by this mistake in 2014.
本文标签: categoriesadd woocommerce archive description if exist
版权声明:本文标题:categories - add woocommerce archive description if exist 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744521963a2610508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论