[英]if control on Wordpress
I need to insert an "if" control in my wordpress code because I want that this checkbox appears only with specific user. 我需要在我的wordpress代码中插入一个“if”控件,因为我希望这个复选框只出现在特定的用户身上。 But I receive always an error.
但我总是收到一个错误。
<?php if ( !current_user_can('edit_users') ) {
<?php $featured_checked = get_post_meta( $post->ID, '_elist_featured', true ) && 'on' == get_post_meta( $post->ID, '_elist_featured', true ) ? ' checked="checked"' : ''; ?><label for="_elist_featured" class="selectit"><input name="_elist_featured" type="checkbox" id="_elist_featured" <?php echo esc_html( $featured_checked ); ?>><?php esc_html_e( 'This listing is featured.' ); ?></label></div>
} ?>
You need to properly open and close the PHP tags surrounding your IF
statement and closing curly brace. 您需要正确打开和关闭
IF
语句周围的PHP标记并关闭大括号。 Your current code is missing ?>
at the end of the first line and <?php
at the beginning of the last 您当前的代码是丢失的
?>
在第一行的末尾和<?php
在最后一行的开头
Incorrect: 不正确:
<?php if ( !current_user_can('edit_users') ) {
<-- your HTML and PHP -->
} ?>
Correct: 正确:
<?php if ( !current_user_can('edit_users') ) { ?>
<-- your HTML and PHP -->
<?php } ?>
You are using additional <?php
tags in your code. 您在代码中使用了其他
<?php
标记。
FYI- try to use a good editor to fix these kinda bugs 仅供参考 - 尝试使用一个好的编辑器来解决这些问题
<?php if ( !current_user_can('edit_users') ) {
$featured_checked = get_post_meta( $post->ID, '_elist_featured', true ) && 'on' == get_post_meta( $post->ID, '_elist_featured', true ) ? ' checked="checked"' : '';
?>
<label for="_elist_featured" class="selectit">
<input name="_elist_featured" type="checkbox" id="_elist_featured" <?php echo esc_html( $featured_checked ); ?>>
<?php esc_html_e( 'This listing is featured.' ); ?>
</label>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.