根据登录显示用户名
Show username depending on login
这是为建立 wordpress 评论系统的人准备的。此代码确定单击 "reply."
后的 post
目标是获取在 "author" 表单中输入的名称或用户身份(通过 php),具体取决于此人是否已登录。
success: function(data, textStatus){
if(data=="success"){
var avatar = "<?php echo get_avatar($id_or_email, 48,'/Avatar.png' ); ?>";
var author = "<?php if ( is_user_logged_in() ) : ?><?php echo $user_identity; ?><?php else :?>"jQuery('#author').val() ;
var authorurl = "<?php the_author_meta( 'user_url'); ?>";
var timestamp = "<?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?>";
var commenttext = jQuery('#comment').val();
jQuery('<li class="new-post">'+'<div class="comment-author vcard">'+avatar+
'<div class="comment-meta">'+'<b>'+'<a href="authorurl">'+author+'</b>'+'</a>'+
'<div class="comment-time-stamp">'+timestamp+'</div>'+'</div>'+'</div>'+
'<div class="comment-text">'+'<p>'+'<pre class="new-post-pre">'+commenttext+'</pre>'+'</p>'+'</div>'+'</li>').insertBefore(respond);
statusdiv.html('<p class="ajax-success" ></p>');
}
这就是问题所在:
var author = "<?php if ( is_user_logged_in() ) : ?><?php echo $user_identity; ?><?php else :?>"jQuery('#author').val() ;
您的 PHP 代码中缺少 endif
并且双引号在错误的位置(如果我很好地理解问题):
var author = <? if ( is_user_logged_in() ) : echo '"'.$user_identity.'"'; else: ?> jQuery('#author').val() <? endif; ?>;
这是为建立 wordpress 评论系统的人准备的。此代码确定单击 "reply."
后的 post目标是获取在 "author" 表单中输入的名称或用户身份(通过 php),具体取决于此人是否已登录。
success: function(data, textStatus){
if(data=="success"){
var avatar = "<?php echo get_avatar($id_or_email, 48,'/Avatar.png' ); ?>";
var author = "<?php if ( is_user_logged_in() ) : ?><?php echo $user_identity; ?><?php else :?>"jQuery('#author').val() ;
var authorurl = "<?php the_author_meta( 'user_url'); ?>";
var timestamp = "<?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?>";
var commenttext = jQuery('#comment').val();
jQuery('<li class="new-post">'+'<div class="comment-author vcard">'+avatar+
'<div class="comment-meta">'+'<b>'+'<a href="authorurl">'+author+'</b>'+'</a>'+
'<div class="comment-time-stamp">'+timestamp+'</div>'+'</div>'+'</div>'+
'<div class="comment-text">'+'<p>'+'<pre class="new-post-pre">'+commenttext+'</pre>'+'</p>'+'</div>'+'</li>').insertBefore(respond);
statusdiv.html('<p class="ajax-success" ></p>');
}
这就是问题所在:
var author = "<?php if ( is_user_logged_in() ) : ?><?php echo $user_identity; ?><?php else :?>"jQuery('#author').val() ;
您的 PHP 代码中缺少 endif
并且双引号在错误的位置(如果我很好地理解问题):
var author = <? if ( is_user_logged_in() ) : echo '"'.$user_identity.'"'; else: ?> jQuery('#author').val() <? endif; ?>;