修改WordPress中文工具包:最新评论、日志
Wordpress中文工具包很好用,但是最新评论以及最新发布的文章显示不美观,在这里修改一下,效果见本文右边侧栏:
参见代码中的注释:
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
//去除blockquote带来的引用评论
// remove blockquote, such as: [Comment ID #5 Will Be Quoted Here]
$temp = eregi_replace('\[Comment ID #[0-9]+ Will Be Quoted Here\]', '', $comment_content);
$comment_excerpt =substr($temp, 0, $maxlen);
if (strlen($temp) >= $maxlen)
{
//只有长度不足的时候才需要trim,否则不需要,这样就避免了短评论最后一个字被截掉的问题
$comment_excerpt = utf8_trim($comment_excerpt);
$elipse = '...';
}
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$post = &get_post($comment->ID);
$title = $post->post_title;
//一切为了美观
$output .= $before;
$output .= '+ <a href="' . $permalink . '" title="显示用户[' . $comment->comment_author . ']的评论">' . 'Re:' . $title . '</a>: ';
$output .= '<br/> ' . $comment_excerpt;
if ($elipse != '') {
$output .= '<a href="'. $permalink . '" title="查看详细评论内容">' . '...' . '</a>';
}
$output .= '<div align="right">---' . $comment->comment_author . '</div>';
$output .= $after;
}
get_recent_post这里不再列出,也是做了一个summary,然后作为鼠标悬停信息提示。
Tags:[tag]modified, wordpress, recent, post, comment[/tag]
links: 南大情杀-割头-这个世界真疯狂
-
南大情杀-割头-这个世界真疯狂
改进wordpress简单编辑器quicktags
一直觉得wordpress本身的可视化编辑器慢,后来搞了一个editor monkey,更慢,特别是通过北京的网通打开的时候,够时间煮一杯咖啡了。
突然发现原来wordpress本身的简单编辑器很好用,虽然没有那么多的色彩,没有可视化(一般用不到),但是还是很简洁高效,唯一不爽的是上面不是我想要的tag
于是修改了一下quicktags.js源码:
加入了tag, coolcode, color, bk_color, 注释掉了more/page/Close Tags/lookup
这是修改以后的工具条:

下载(右键目标另存为): http://www.2maomao.com/blog/wp-content/uploads/quicktags.js
使用方法: 直接替换wp-include\js下面的quicktags.js文件
部分代码(以coolcode tag为例):
前面:
new edButton('ed_code'
,'coolcode'
,''
,'\n\n'
,'c'
); //special case
中间:
document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertCoolCode(edCanvas, ' + i + ');" value="' + button.display + '" />');
}
最后:(其中的<是为了coolcode嵌套,代表<
var myValue = prompt('Input Language:', 'html');
if (myValue) {
edButtons[i].tagStart = '\n<coolcode lang="' + myValue + '">\n';
edInsertTag(myField, i);
}
}
搞定。
附:quicktags的快捷键总是会出错,乱贴一气,不知道怎么搞的
Tags:[tag]quicktags, tags, coolcode, javascript, wordpress[/tag]
测试转载,转贴,zz,zt
这是个测试贴:
只要标题中出现了“转贴, 转载, zz, zt”中的一个,就不会出现作者以及链接声明了
顺便测试修改过的编辑器
this is a test for coolcode button in the editor
Update:考虑到del.iciu.us自动发帖,加入了”links for”过滤
Tags:[tag]test, 转贴, 转载, zt, zz, 声明, 编辑器[/tag]
文章前加入作者名和本文链接
考虑到文章会被转载,在原创文章前面加入了作者和本文链接声明:
在代码(index.php):
前面加入了
<?php if (strpos($thetitle, '转贴') === false) { ?>
<?php if (strpos($thetitle, '转载') === false) { ?>
<?php if (strpos($thetitle, 'zz') === false) { ?>
<?php if (strpos($thetitle, 'zt') === false) { ?>
<font color=#cccccc>
作者:兔毛猫(2maomao.com) 链接:<?php the_permalink() ?>
</font>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
其中的条件判断提供了在转贴别人的文章时,不加入作者和本文链接声明的方法:
发表文章时在标题中加入’转贴’,”转载”,’zz’或者’zt都会自动去除该声明。
目前存在的问题:
1. 不会RSS中显示
这个做起来不难,修改rss.php应该就可以实现,但是还是算了,因为订阅RSS的用户,转载的时候都应该知道加原始链接吧。
而且订阅RSS本身就是为了方便,何必加个链接污染视野呢。
2. 有可能不是在标题开头出现转载,并且是原创帖
懒得改了,可以改成前两个字加冒号等等等等,这都不严重,而且很少见
Tags:[tag]转载, 转贴, zz, zt, 声明[/tag]



