WordPress 匿名评论 二
前不久发表了一篇简单WordPress 匿名评论的文章,近来又进行了一次修改,不少网向我要教程, 最近好像又没什么好写的,就写写这个吧。
演示 — 跳到评论区
开始啦~~
打开comments.php 文件
找到下面的代码(不同主题可能有所不同,但大致一样)
<input id="author" name="author" size="22" type="text" value="<?php echo esc_attr($comment_author); ?>" tabindex="1" /> /> <label for="author"><small><!--?php _e('Name', 'kubrick'); ?--> <!--?php if ($req) _e("(required)", "kubrick"); ?--></small></label> <input id="email" name="email" size="22" type="text" value="<?php echo esc_attr($comment_author_email); ?>" tabindex="2" /> /> <label for="email"><small><!--?php _e('Mail (will not be published)', 'kubrick'); ?--> <!--?php if ($req) _e("(required)", "kubrick"); ?--></small></label> <input id="url" name="url" size="22" type="text" value="<?php echo esc_attr($comment_author_url); ?>" tabindex="3" /> <label for="url"><small><!--?php _e('Website', 'kubrick'); ?--></small></label>
复制下面的代码替换之
<script src="http://fw.qq.com/ipaddress" type="text/javascript"><!--mce:0--></script> <div id="nim" style="display: none;"> 你好!<strong>匿名</strong> 欢迎评论指点 <a title="重新填写资料" onclick="$('#nim').slideUp(600);$('#comment-info').slideDown(600);" href="javascript:">编辑信息»</a> <em>* 匿名评论需审核才能展示,建议留下你的联系方式。</em></div> <div id="comment-info"> <li> <input id="author" name="author" type="text" value="<?php echo esc_attr($comment_author); ?>" /> <label for="author"><!--?php _e('Name'); ?--> <!--?php if ($req) _e('(required)'); ?--></label> <!--?php if (!isset($_COOKIE['comment_author_'.COOKIEHASH])){ ?--> <label> <input id="anymous" name="anymous" type="checkbox" /> 匿名</label> <!--?php } ?--></li> <li> <input id="email" name="email" type="text" value="<?php echo esc_attr($comment_author_email); ?>" /> <label for="email"><!--?php _e('Mail (will not be published)');?--><!--?php if ($req) _e('(required)'); ?--></label></li> <li> <input id="url" name="url" type="text" value="<?php echo esc_attr($comment_author_url); ?>" /> <label for="url"><!--?php _e('Website'); ?--></label></li> </div> <!--加载jquery库--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js" type="text/javascript"><!--mce:1--></script> <!--如主题已加载,这段可删除--> <script type="text/javascript"><!--mce:2--></script> <!--?php if ( $comment_author != "" ) : ?--> <script type="text/javascript"><!--mce:3--></script> <!--?php endif; ?-->
如有其它的好办法欢迎讨论.
声明:
本文由Yin发表, 采用 BY-NC-SA 协议进行授权. 如蒙转载请注明转自:尹鹏飞's Blog™

锅,我很笨,这个JS代码要查到什么地方?是放在主题的js目录下面吧?
<public:attach event="ondocumentready" onevent="CSSHover()" /><script>
/**
* Whatever:hover - V3.11
* http://www.xs4all.nl/~peterned/
*
* Copyright (c) 2009 Peter Nederlof
* Licensed under the LGPL license
* http://creativecommons.org/licenses/LGPL/2.1
*/
window.CSSHover=(function(){var m=/(^|\s)((([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active|focus))/i;var n=/(.*?)\:(hover|active|focus)/i;var o=/[^:]+:([a-z\-]+).*/i;var p=/(\.([a-z0-9_\-]+):[a-z]+)|(:[a-z]+)/gi;var q=/\.([a-z0-9_\-]*on(hover|active|focus))/i;var s=/msie (5|6|7)/i;var t=/backcompat/i;var u={index:0,list:['text-kashida','text-kashida-space','text-justify'],get:function(){return this.list[(this.index++)%this.list.length]}};var v=function(c){return c.replace(/-(.)/mg,function(a,b){return b.toUpperCase()})};var w={elements:[],callbacks:{},init:function(){if(!s.test(navigator.userAgent)&&!t.test(window.document.compatMode)){return}var a=window.document.styleSheets,l=a.length;for(var i=0;i<l;i++){this.parseStylesheet(a[i])}},parseStylesheet:function(a){if(a.imports){try{var b=a.imports;var l=b.length;for(var i=0;i<l;i++){this.parseStylesheet(a.imports[i])}}catch(securityException){}}try{var c=a.rules;var r=c.length;for(var j=0;j<r;j++){this.parseCSSRule(c[j],a)}}catch(someException){}},parseCSSRule:function(a,b){var c=a.selectorText;if(m.test(c)){var d=a.style.cssText;var e=n.exec(c)[1];var f=c.replace(o,'on$1');var g=c.replace(p,'.$2'+f);var h=q.exec(g)[1];var i=e+h;if(!this.callbacks[i]){var j=u.get();var k=v(j);b.addRule(e,j+':expression(CSSHover(this, "'+f+'", "'+h+'", "'+k+'"))');this.callbacks[i]=true}b.addRule(g,d)}},patch:function(a,b,c,d){try{var f=a.parentNode.currentStyle[d];a.style[d]=f}catch(e){a.runtimeStyle[d]=''}if(!a.csshover){a.csshover=[]}if(!a.csshover[c]){a.csshover[c]=true;var g=new CSSHoverElement(a,b,c);this.elements.push(g)}return b},unload:function(){try{var l=this.elements.length;for(var i=0;i<l;i++){this.elements[i].unload()}this.elements=[];this.callbacks={}}catch(e){}}};var x={onhover:{activator:'onmouseenter',deactivator:'onmouseleave'},onactive:{activator:'onmousedown',deactivator:'onmouseup'},onfocus:{activator:'onfocus',deactivator:'onblur'}};function CSSHoverElement(a,b,c){this.node=a;this.type=b;var d=new RegExp('(^|\\s)'+c+'(\\s|$)','g');this.activator=function(){a.className+=' '+c};this.deactivator=function(){a.className=a.className.replace(d,' ')};a.attachEvent(x[b].activator,this.activator);a.attachEvent(x[b].deactivator,this.deactivator)}CSSHoverElement.prototype={unload:function(){this.node.detachEvent(x[this.type].activator,this.activator);this.node.detachEvent(x[this.type].deactivator,this.deactivator);this.activator=null;this.deactivator=null;this.node=null;this.type=null}};window.attachEvent('onbeforeunload',function(){w.unload()});return function(a,b,c,d){if(a){return w.patch(a,b,c,d)}else{w.init()}}})();
</script>
这是我的JS文件夹下的csshover3.htc文件里面的代码,要添加在什么位置呢?锅,我很菜的,一定一定要教我!
你可以新建一个文件名为nim.js,并复制js代码到这个文件中 再放入到js目录下,然后在主题目录打开footer.php 在
</body>标签前加入<script src="<?php bloginfo('template_url'); ?>/js/nim.js" type="text/javascript"></script>我把代码(不是js)覆盖之后,提示我说最后一行代码语法错误,我想问一下,这和我是windows主机有关系吗?
由于我在后台开启了WordPress 自动校正错误的 XHTML 代码功能,代码变乱了,不好意思。
现在代码已重新整理,直接覆盖即可。
哥,我恨你!折腾了一个晚上…
兄弟实在对不住
还没弄好呀,要不你把你模板发我,给你弄一下
效果挺好的,就是有点麻烦
不麻烦,就是代码有点长
哥,其实我就在等你这句话,这就发给你!
爱你啊!你就是我的大湿!!!
不要夸哥,哥平时很低调!
欧卡诺小编来了支持下先
谢谢支持
这个功能挺不错的,哪天也试一试!
随便试
测试一下看看
测试匿名评论
呵呵
http://www.tsqw.com/
欢迎来小站看看。 – -,php程序员就是牛B
欢迎各位新老客户咨询。投票QQ:6153197 咨询热线:15012580335
快速拉票投票服务 请访问网站:http://www.80toupiao.com