我想在一个数组中获取woocommerce产品的产品标签,用它做if/else逻辑(in_array),但我的代码不起作用:
<?php
$aromacheck = array() ;
$aromacheck = get_terms( 'product_tag') ;
// echo $aromacheck
?>
Run Code Online (Sandbox Code Playgroud)
当回显$ aromacheck时,我只获得空数组,尽管产品标签存在 - 在帖子类中可见.
如何正确获取阵列中的产品标签?
解决方案(感谢Noman和nevius):
/* Get the product tag */
$terms = get_the_terms( $post->ID, 'product_tag' );
$aromacheck = array();
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$aromacheck[] = $term->slug;
}
}
/* Check if it is existing in the array to output some value */
if (in_array ( "value", $aromacheck ) …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我想让文本链接带有border-bottom-bottom,并像这样设置CSS
a:hover {
color: #492512;
border-bottom: 2px dashed #94705A;
}
Run Code Online (Sandbox Code Playgroud)
问题在于,包装在链接中的图像也具有此边框底,例如。
<a href="home">
<img src="logo.jpg" alt="Logo" class="logo-img">
</a>
Run Code Online (Sandbox Code Playgroud)
如何将仅用于文本链接的a:hover定位?纯CSS将是更可取的。
我有一个jQuery脚本,它收集变量中复选框的值:
var 1_val = $("input[type='checkbox'][name='val_1']").prop( "checked" );
var 2_val = $("input[type='checkbox'][name='val_2']").prop( "checked" );
Run Code Online (Sandbox Code Playgroud)
然后我在一封邮件中输出这些邮件,通过电子邮件发送:
...<strong>Value 1</strong>: 1_val + '<br /><strong>Value 2</strong>: ' + 2_val + '<br />...
Run Code Online (Sandbox Code Playgroud)
但是在消息体中我得到了布尔值为true/false的字符串,我想要制作一些更加用户友好的消息,如是/否.我该怎么改变它?