A easy way to add copyright information automatically into post(English Version英文版)

 Several weeks ago, I decided to write about two blog posts every day. I used to write copyright information manually in the post. Apparently, it's better to let the machine do this type of trivial work automatically. So, I searched the plugins to try to find a convenient one. Indeed, I found the plugin named "add post URL" which is able to help the author to insert copyright information into the post. When I clicked the 'DETAIL' button to see more. A warning message popped up: "This plugin has not been tested with your current version of WordPress". I was scared. Because I once had a bad experience about how untested plugin ruined my wordpress as a whole. So, the option of using plugin to insert copyright information was ruled out. ...

June 17, 2012 · 4 min · kamus

一个更方便的在wordpress博客的文章中自动添加版权信息的方法(Chinese Version 中文版)

从半个月前,我决定每天都写两篇左右篇客,或者原创,或者翻译。对于国内的抄袭风气,大家都很清楚,转载别人的文章时把别人的版权信息改成自己的。虽然没有非常好的办法对付抄袭。但至少也需要摆明原创作者的态度还是很必要的。 一开始,我在每篇博文里手动添加版权信息和链接。虽然工作量不算太大,但对于这种高度重复性的工作,能让机器做还是交给机器做吧。 首先当然想到的是找相关自动插入版权信息的wordpress插件,虽然也找到一款。名字叫add post,如果没有记错的话!点击Detail查看详细说明的时候发现已经很久没有更新了,而且有一个警告说对于我当前使用的wordpress版本没有经过测试。没有经过测试这句话吓到我了,我不想因为一个插件给我的博客引用不稳定性。于是放弃了使用插件。 不能使用插件那就只能自己改代码。谷歌了一下,自然搜索到前人写的相关贴子。贴子介绍说找到single.php文件。single.php文件是发贴发贴的文件,我不确定是不是文件名和所有的主题相关,会不会因为使用不同的主题,这个文件名会不太一样。然后找到这段代码: <?php the_content(); ?> <!– Pagination for Multi-page posts ~~~ –> <?php wp_link_pages('before=Pages:&after= '); // if this is a multipage post then show the navigation ?>   然后在这段代码的<?php the_content(); ?> 下面插入生成版本信息的代码。但问题是,这种方法并不可靠。非常多的博客使用了其它相关的插件会干扰这种做法。比如,我使用了一个自动生成相关文章列表的插件。于是版本信息被加到了相关文章列表下面,离真正的文章正文有很远的距离。这必不令人满意。另有文章指出可以修改function.php文件,自定义一个和the_content()类似的函数,然后把single.php中的the_content()函数替换掉来完成这个任务。我看了一下,不太满意。修改的地方超过了两个文件,觉得改动有点多。另外写的那个自定义函数对于没有太多wordpress的代码经验的人来讲并不是非常容易读懂。至少我就不明白那个自定义函数的参数的意义,应该和wordpress的标准代码相关。另外,我很怀疑如果用了这种方式,可以会使我的显示相关博文列表的插件失效。一下子没有找到非常好的解决方法。于是去吃晚饭。吃完晚饭后回到电脑前突然来了灵感。可以在用替换字符串的方法增加版权信息呀。想法是这样的。 1. 在编辑文章的时候,在你需要插入版本信息的地方加入特殊的字符串。比如我选择了在每篇博文最后敲入字符串 “copyright  ykyi.net” 2. 在发表文章阶段把这个特殊字符串替换成html代码,显示你的版本信息。 是不是既简单又灵活呢! 注意要实现这个想法,需要明白 the_content() 和 get_the_content() 两个wordpress函数的区别。在调用the_content()函数的时候,文章的内容就已经打印出来了。但get_the_content()是把文章的内容做为函数返回值返回。所以在修改single.php文件时,要把 the_content()用get_the_content()函数代替。 下面贴出我的代码。看官如果需要可以修改相应部分: <?php $thread_content = get_the_content();  $thread_permalink = get_permalink(); $thread_title = get_the_title($post_id); $dogeye_copyright = "除非明确声明,本站所以文章均为DogEye博客原创或者自主翻译。如转载,请注明出处。$thread_title $thread_permalink"; $thread_content = str_replace('copyright  ykyi.net', $dogeye_copyright, $thread_content); echo $thread_content; ?>   代码应该非常容易读懂了。而且你可以非常灵活地控制要插入的位置,还可以灵活决定插入多处版本声明。   copyright ykyi.net

June 15, 2012 · 1 min · kamus