簡體   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