wordpress的@回复实现

2011-11-15 | 夜光 | IT记录| 发表评论

一、在主题functions.php文件中添加如下代码:

/*reply*/
function at_reply() {
?>
<a href="#respond" onclick="at_reply('<?php comment_ID() ?>','<?php comment_author();?>')" style="cursor:pointer;">回复</a>
<?php
}

二、在主题comments.php的评论列表处添加如下代码:

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/at-reply-ylife.js"></script>

其中at-reply-ylife.js文件内容如下:

/*reply*/
function at_reply(commentID,author) {
var nNd='<a href="#comment-'+commentID+'">'+'@'+author.replace(/\t|\n|\r\n/g, "")+' </a>'+'\n';
var myField;
if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
myField = document.getElementById('comment');
} else {
return false;
}
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = nNd;
myField.focus();
}
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
var cursorPos = endPos;
myField.value = myField.value.substring(0, startPos)
+ nNd
+ myField.value.substring(endPos, myField.value.length);
cursorPos += nNd.length;
myField.focus();
myField.selectionStart = cursorPos;
myField.selectionEnd = cursorPos;
}
else {
myField.value += nNd;
myField.focus();
}
}

三、在需要显示回复按钮的地方用如下代码调用:

<?php at_reply(); ?>
本文标签:
本文链接: http://boliquan.com/wordpress-at-reply/
版权所有: 玻璃泉, 转载请注明本文出处。

发表评论

您的昵称 *

您的邮箱 *

您的网站

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif

Protected by WP Anti Spam