Archive for the ‘WordPress’ Category

Wordpress2.9下使用Simple Tags

目前Simple Tags插件(1.6.6版本)暂时不兼容于 Wordpress 2.9,
在论坛上发了一条公告,提醒大家谨慎升级。结果,意外的换来一个解决方案。
表面上说不支持,其实wordpress2.8.6和wordpress2.9的构架变化不是太大,可以强开:

修改 wp-content/plugins/simple-tags/simple-tags.php

if ( strpos($wp_version, '2.7') !== false || strpos($wp_version, '2.8') !== false )

变更为

if ( strpos($wp_version, '2.7') !== false || strpos($wp_version, '2.9') !== false )

绕开版本的检测即可,测试正常,可以放心使用。

wordpress修改评论者链接结构

nofollow标签的算法变更和百度对该标签的不认可,导致wordpress评论区域最好也据此来做相应的调整。使用robots.txt对自身地址进行屏蔽,从而规避非法链接对自身权重的影响。

其实之前已经做过了相应的改动,只是WP版本一升级,得,把我的改动覆盖了……
做个备忘,并重新操作一遍:

1.打开wp-includes文件夹下的comment-template.php文件
2.找到$return = “<a href=’$url’ rel=’external nofollow’ class=’url’>$author</a>”;语句
3.链接修改为 a href=’/go.php?$url’
4.替换上传

同理,可以修改wp-includes文件夹下的formatting.php文件,修改评论中写到的链接结构。
return $matches[1] . “<a href=\”$url\” rel=\”nofollow\”>$url</a>”;

go.php写法:

  1. <?php
  2. header("location: ".$_SERVER['REDIRECT_QUERY_STRING']);
  3. ?>

wordpress关闭缩略图

wordpress默认会把一些比较大的图片进行裁切压缩处理,自动生成缩略图。
但是我这里并不需要该功能,为此在后台找了一下解决的办法:

登陆wp后台,在”设置==>媒体”中,将图像大小全部改为0

Turn-Off-Image-Thumbnails-in-WordPress

wordpress模板结构及页面函数调用

先说今天遇到的一个问题,
我在wordpress模板目录下新建了一个PHP文件,service.php,想要调用<?php get_footer(); ?>函数,得到反馈结果

Fatal error: Call to undefined function get_footer() in D:\web\blog\wp-content\themes\bettersun\service.php on line 73

查了一下解决办法是在该页面头部引入:

require_once('site/wp-config.php');

另外,翻到一些常用的wordpress模板结构及页面函数调用参数,以备后需:

wordpress-php
阅读全文 »

在wordpress主题评论中添加@reply功能

@reply回复功能,没必要再添加一个插件来做。我们可以通过修改当前所调用的wordpress主题来实现该功能。

方法如下:

一、在评论页comments.php添加如下JS代码:

  1. <script language="javascript">
  2. //<![CDATA[
  3. function to_reply(commentID,author) {
  4. var nNd='@'+author+':';
  5. var myField;
  6. if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
  7. myField = document.getElementById('comment');
  8. } else {
  9. return false;
  10. }
  11. if (document.selection) {
  12. myField.focus();
  13. sel = document.selection.createRange();
  14. sel.text = nNd;
  15. myField.focus();
  16. }
  17. else if (myField.selectionStart || myField.selectionStart == '0') {
  18. var startPos = myField.selectionStart;
  19. var endPos = myField.selectionEnd;
  20. var cursorPos = endPos;
  21. myField.value = myField.value.substring(0, startPos)
  22. + nNd
  23. + myField.value.substring(endPos, myField.value.length);
  24. cursorPos += nNd.length;
  25. myField.focus();
  26. myField.selectionStart = cursorPos;
  27. myField.selectionEnd = cursorPos;
  28. }
  29. else {
  30. myField.value += nNd;
  31. myField.focus();
  32. }
  33. }
  34. //]]>
  35. </script>

二、在functions.php中加入如下代码

  1. function to_reply() {
  2. ?>
  3. <a onclick='to_reply("<?php comment_ID() ?>", "<?php comment_author();?>")' href="#respond" style="cursor:pointer;"/>[@reply]</a>
  4. <?php
  5. }

三、在评论页<?php comment_author_link() ?>后边添加”回复按钮”

<?php to_reply(); ?>
Page 1 of 512345
崔凯的博客
Powered by WordPress | Theme by ck web design | TOP 顶部
Copyright © 崔凯的博客 All rights reserved. Valid XHTML & CSS. 京ICP备09029324号.