我使用此代码在WordPress中显示用户配置文件:
<?php
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if ( ($current_user instanceof WP_User) ) {
echo \'<div class="omid-header-proimg">\'.get_avatar( $current_user->ID, 64 ).\'</div>\';
echo \'<div class="omid-header-protext">\'.esc_html( $current_user->display_name ).\'</div>\';
echo \'<div class="omid-logpanel"><a href="https://test.com/panel">panel</a></div>\';
}
}
?>
但是当我想在用户未登录时使用以下代码时,将不会加载该站点。问题出在哪里?
<?php
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if ( ($current_user instanceof WP_User) ) {
echo \'<div class="omid-header-proimg">\'.get_avatar( $current_user->ID, 64 ).\'</div>\';
echo \'<div class="omid-header-protext">\'.esc_html( $current_user->display_name ).\'</div>\';
echo \'<div class="omid-logpanel"><a href="https://test.com/panel">panel</a></div>\';
}
}
else {
echo \'<div class="omid-header-proimg"><img src="\'. bloginfo(\'template_url\') .\'/images/omid-nonsignin.png"></div>\'
echo \'<div class="omid-logpanel"><a href="https://test.com/panel">login</a></div>\'
}
?>
最合适的回答,由SO网友:ChristopherJones 整理而成
您的最后一行缺少分号:
echo \'<div class="omid-header-proimg"><img src="\'. bloginfo(\'template_url\') .\'/images/omid-nonsignin.png"></div>\';
echo \'<div class="omid-logpanel"><a href="https://test.com/panel">login</a></div>\';