繁体   English   中英

如果控制Wordpress

[英]if control on Wordpress

我需要在我的wordpress代码中插入一个“if”控件,因为我希望这个复选框只出现在特定的用户身上。 但我总是收到一个错误。

<?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> 

    } ?>

您需要正确打开和关闭IF语句周围的PHP标记并关闭大括号。 您当前的代码是丢失的?>在第一行的末尾和<?php在最后一行的开头

不正确:

<?php if ( !current_user_can('edit_users') ) {
<-- your HTML and PHP -->
} ?>

正确:

<?php if ( !current_user_can('edit_users') ) { ?>
<-- your HTML and PHP -->
<?php } ?>

您在代码中使用了其他<?php标记。

仅供参考 - 尝试使用一个好的编辑器来解决这些问题

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM