这是为人们建立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() ;发布于 2015-01-20 01:14:47
您在PHP代码中缺少了endif,在错误的地方有一个双引号(如果我完全理解这个问题):
var author = <? if ( is_user_logged_in() ) : echo '"'.$user_identity.'"'; else: ?> jQuery('#author').val() <? endif; ?>;https://stackoverflow.com/questions/28036140
复制相似问题