admin管理员组文章数量:1130349
With this code:
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
}
?>
I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.
Tried
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
} else {
$class .= ' coupon-hidden';
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );}
$meta == '';
$button_text = 'Angebot anzeigen';
}
?>
But just getting empty page.
With this code:
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
}
?>
I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.
Tried
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
} else {
$class .= ' coupon-hidden';
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );}
$meta == '';
$button_text = 'Angebot anzeigen';
}
?>
But just getting empty page.
Share Improve this question asked Nov 22, 2018 at 18:52 joloshopjoloshop 211 silver badge8 bronze badges 4 |1 Answer
Reset to default 0First off, as I mentioned in the comment, you got a syntax error here, where there's an unwanted }:
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} // <- that }
(Updated answer — Previous code were removed since they didn't work for you.)
So if you want to show the special text when $clpr_options->coupon_code_hide does not evaluate to a true and that the field clpr_coupon_code is empty; try this:
<?php if ( $clpr_options->coupon_code_hide ) {
$class .= ' coupon-hidden';
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );
// If clpr_coupon_code is empty.
if ( ! $meta ) {
$button_text = 'Angebot anzeigen';
// If clpr_coupon_code is not empty.
} else {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
}
}
?>
With this code:
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
}
?>
I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.
Tried
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
} else {
$class .= ' coupon-hidden';
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );}
$meta == '';
$button_text = 'Angebot anzeigen';
}
?>
But just getting empty page.
With this code:
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
}
?>
I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.
Tried
<?php if ( $clpr_options->coupon_code_hide ) {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
$class .= ' coupon-hidden';
} else {
$class .= ' coupon-hidden';
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );}
$meta == '';
$button_text = 'Angebot anzeigen';
}
?>
But just getting empty page.
Share Improve this question asked Nov 22, 2018 at 18:52 joloshopjoloshop 211 silver badge8 bronze badges 4-
There's an unwanted
}after theget_post_meta()call -true );}, and what is that$meta == '';doing? – Sally CJ Commented Nov 22, 2018 at 19:46 -
removed the
}the$meta == ' ';is checking if meta is empty. – joloshop Commented Nov 22, 2018 at 19:56 - still not working just stuck – joloshop Commented Nov 22, 2018 at 20:14
- Check and try my answer? – Sally CJ Commented Nov 22, 2018 at 20:31
1 Answer
Reset to default 0First off, as I mentioned in the comment, you got a syntax error here, where there's an unwanted }:
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} // <- that }
(Updated answer — Previous code were removed since they didn't work for you.)
So if you want to show the special text when $clpr_options->coupon_code_hide does not evaluate to a true and that the field clpr_coupon_code is empty; try this:
<?php if ( $clpr_options->coupon_code_hide ) {
$class .= ' coupon-hidden';
$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );
// If clpr_coupon_code is empty.
if ( ! $meta ) {
$button_text = 'Angebot anzeigen';
// If clpr_coupon_code is not empty.
} else {
$button_text = fl_get_option( 'fl_lbl_show_coupon' );
$button_text = '<i class="icon-lock"></i>' . $button_text;
}
}
?>
本文标签: phpShow different button text if no content
版权声明:本文标题:php - Show different button text if no content 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749159101a2325097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


}after theget_post_meta()call -true );}, and what is that$meta == '';doing? – Sally CJ Commented Nov 22, 2018 at 19:46}the$meta == ' ';is checking if meta is empty. – joloshop Commented Nov 22, 2018 at 19:56