设为首页 收藏本站
查看: 676|回复: 0

[经验分享] Wordpress 的 comments-popup.php 文件有什么用?

[复制链接]

尚未签到

发表于 2017-4-7 08:53:58 | 显示全部楼层 |阅读模式
  在 WP 的 theme 中有个 comments.php 文件,是评论模板文件。但另一个名字相关的 comments-popup.php 文件,一直不知道它有什么用。甚至删除了它,也没见系统有什么反常的。
  其实,它还是有用的,就是点击文章的“评论”,可以弹出该页面,在里边填写评论。但因为“弹出评论页面”的功能默认是被关闭的,所以很多人不了解它。要打开弹出评论页面的功能,编辑 header.php 文件,看到第 21 行(WP2.9.1版本):
  <?php //comments_popup_script(); // off by default ?>
  这里就是开关,把该句的注释去掉。然后刷新博客主页面,会看到代码的 head 部分多了 js 脚本:
  <script type='text/javascript'>
function wpopen (macagna)
{
window.open(macagna, '_blank', 'width=400,height=400,scrollbars=yes,status=yes');
}
</script>
  评论链接的脚本变为:
  <div class="feedback">
<a href="http://.../?comments_popup=230"  title="...">评论(0)</a>
</div>
  注意js脚本  写的很巧妙,在不改变链接结构的情况下,就加了 onclick 事件函数,就改变了链接的打开行为。而不是写为:
  <a href="#"  title="...">评论(0)</a>
  发现本技巧,参考了老外的一篇文章:
(地址:http://playworkplay.com/blog/understanding-comments-popupphp/)
  Understanding comments-popup.php
  28.01.2008
  I have a confession to make.
  Up until now, I didn’t have any idea how comments-popup.php works. Oh, it’s not like I haven’t done any research. The Codex’s Theme Development page, for instance, explains this file as:
  The popup comments template. If not present, comments-popup.php from the “default” Theme is used.
  And it doesn’t link to any specific page explaining more about it. On another page, Using Themes, the information is even more sparse:
  Popup Comments Template = comments-popup.php
  For quite a long time, my understanding is that this file is used if, somewhere within WordPress, the option to display comments as a popup is activated. When that magic switch is on, people who click the comment link will get a popup window with the comment area inside it. The question is, where on earth do I find that option?
  Oh, don’t ask me how many hours I’ve spent looking around for it. I’m even tempted to enter the famous Konami Code inside the WP admin area just to see if a secret page will open and show me the magic “Display Comment as Popup” option—it’s really that hard to find!
  And no wonder. I just got the revelation today, and it turns out there’s never been such option within the admin area. Nope. I was digging in the wrong place.
  The option to use comments-popup.php, ladies and gentlemen, depends solely on the presence of a single PHP line inside a theme’s header file. Go open the header.php of the Classic theme (available in any default install of WordPress), line 21 you will see:
  view sourceprint?1.<?php //comments_popup_script(); // off by default ?>Yes! That’s the magic switch. The Holy Grail of Popup Commenting. I uncommented that and, bam, the very first WordPress comment popup appared before my very eyes. Try it.
  By searching for that PHP function into the Codex, I found this small but complete explanation about popup comments, which I wished I’ve found before.
  Anyways, it’s also interesting to note that many, many themes out there have comments-popup.php inside them but no comments_popup_script() function, making it practically useless. It’s not even available within Kubrick, WordPress’s current default theme.
  I’m not sure why comments_popup_script() function is not included within the default theme (not even in commented form like the one inside the classic theme); to me and many others, Kubrick is the first theme we tear apart and learn in the process. Perhaps the usage of popup window is discouraged?
  I’m not sure. But in my case, I’m very likely to leave out the comments-popup.php like I often do. I used to do it out of the fact that I don’t know what it does, and because Sandbox theme—another good theme I learn a lot from—does not have it. But now, after some thinking, I’ll just leave it out for one more reason:
  I’ve never ever visit a WP-powered blog with popup comments (have you?). I’m sure that’s what most users experience as well—we’re already accustomed to the open-new-page-for-comments behavior.
  Better not mess with that.
  
作者:张庆(网眼) 2010-4-6
来自“网眼视界”:http://blog.why100000.com
“十万个为什么”电脑学习网:http://www.why100000.com

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-361270-1-1.html 上篇帖子: php全面获取url地址栏及各种参数 下篇帖子: PHP获取IP地址所在的地理位置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表