原文地址为:https://www.jb51.net/cms/263369.html
本文实例讲述了wordpress主题评论中添加回复的方法。分享给大家供大家参考。具体如下:文章来源地址https://www.yii666.com/blog/318298.html
很多朋友要给自己主题评论加个@reply回复效果,都会选择用插件,其实我们可以完全修改源码来实现,这里就来给大家介绍wordpress主题评论中怎么添加@reply回复.
方法如下:文章来源站点https://www.yii666.com/
一、在评论页comments.php添加如下JS代码:
复制代码
代码如下:
<script language=”javascript”>
//<![CDATA[
function to_reply(commentID,author) {
var nNd=’@’+author+’:’;
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();
}
}
//]]>
</script>
//<![CDATA[
function to_reply(commentID,author) {
var nNd=’@’+author+’:’;
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();
}
}
//]]>
</script>
二、在functions.php中加入如下代码
复制代码
代码如下:
//@reply回复功能
function to_reply() {
?>
<a onclick=’to_reply(“<?php comment_ID() ?>”, “<?php comment_author();?>”)’ href=”#respond” style=”cursor:pointer;”/>[@reply]</a>
<?php
}
?>
function to_reply() {
?>
<a onclick=’to_reply(“<?php comment_ID() ?>”, “<?php comment_author();?>”)’ href=”#respond” style=”cursor:pointer;”/>[@reply]</a>
<?php
}
?>
三、在评论页
复制代码
代码如下:
<?php comment_author_link() ?>
后边添加”回复按钮”,代码如下:
复制代码
代码如下:
<strong><?php to_reply(); ?></strong>
希望本文所述对大家的WordPress建站有所帮助。