王之涣 出塞

就如你所看到的,这个唐诗宋词(chinese poem)插件默认随机显示唐诗300首、宋诗或宋词中的一首。当然了,上面的《出塞》只是图片,真实示例可以查看我的留言板



=== Plugin Name ===
唐诗宋词(chinese poem)

Contributors: LD King
Donate link: null
Tags(有多少写多少,哈哈): tang300,唐诗300首, songproses宋词, song100,宋诗100首, caigentan,菜根谭, dao,道德经, joke,笑话, lunyu,论语, maoshici,毛泽东诗词, maoyulu,毛泽东语录, proverb,谚语, zengguang,增广贤文, poem
Requires at least: 2.6
Tested up to: 2.6.1
Stable tag: 0.2
PHP Requires: 5.2.x
License: GPL v3

== Description ==
这个插件允许在Wordpress中随机显示唐诗宋词, 你可以在widget的配置界面选择需要的模块
This plugin show poetry random in WordPress.

Download
chinese-poem.0.3.zip
chinese-poem.0.2.zip
chinese-poem.0.1.zip
暂时放在Google Code里。也可通过SVN获得:

svn checkout http://nothing-at-all.googlecode.com/svn/tags/chinese-poem_0_3
svn checkout http://nothing-at-all.googlecode.com/svn/tags/chinese-poem_0_2
svn checkout http://nothing-at-all.googlecode.com/svn/tags/chinese-poem_0_1

第一个是0.3版的Tag,主支在 http://nothing-at-all.googlecode.com/svn/trunk/chinese-poem

功能说明[Usage]

0.2版加入了Widget支持,所以只要启用插件,在Widget界面配置即可。

唐诗宋词 widget chinese poem
Widget 配置窗口

同时0.2还加入了一个可以控制刷新时间的函数 show_chinese_poetry,它比原函数多了个 timespan 参数,

< ?php
if (function_exists(show_chinese_poetry))
show_chinese_poetry(array('tang300', 'song100', 'songproses'), TRUE, 30);
?>

这样就可以每隔30分钟更新一次诗词,需要注意的是:使用该函数必须保证插件目录下的 “poem.tmp”文件全局可写(权限为666),可以用命令 chmod 666 poem.tmp 来修改,或者FTP工具也可。
详细使用方法可以参考函数 show_chinese_poem()。自定义模块也挺简单的,需要的可以参考这篇文章: 自定义 个性“唐诗宋词”模块

安装完插件后,默认使用以下的代码,将随机从tang300、song100、songproses三个文件中取出一首诗。也就是在我的留言板中看到的那样,会是唐诗300首、宋诗100首或宋词中的其中之一。


< ?php if (function_exists(show_chinese_poem)) show_chinese_poem(); ?>

杜甫 春望
放在Sidebar里的唐诗

当然,前面的可用模块确实是可以使用的,首先说明一下show_chinese_poem()函数的2个参数:

function show_chinese_poem($modules = array(‘tang300′, ‘song100′, ‘songproses’), $css = TRUE)

第一个参数$modules 是一维数组,插件会在$modules的模块中自动选择一个作为输出; 而$css是布尔型,TRUE表示加载插件的CSS文件。

比如模块中有一个”毛泽东诗词”,我希望只在”毛泽东诗词”中挑选诗词输出,那么可以这么写:

< ?php
if (function_exists(show_chinese_poem))
show_chinese_poem(array('maoshici'));
?>

七律 人民解放军占领南京

此外需要说明的是,输出HTML格式,基本所有模块的输出都和下面的定义差不多,可以据此修改poem.css中的风格。

诗词标题
诗歌作者
诗歌内容

可用模块

  • caigentan: 菜根谭
  • dao: 道德经
  • joke: 笑话集
  • lunyu: 论语
  • maoshici: 毛泽东诗词
  • maoyulu: 毛泽东语录
  • proverb: 谚语
  • song100: 宋诗100首
  • songproses: 宋词
  • tang300: 唐诗300首
  • zengguang: 增广贤文

诗词原始资料来源于chinese-fortune

== Installation ==

  • Upload the Plugin folder to the `/wp-content/plugins/` directory
  • Activate the plugin through the `Plugins` menu in WordPress
  • Add Anywhere: <?php show_chinese_poem() ?>
  • If you need to configure the CSS style of 唐诗宋词(chinese poem), open and edit:
    /wp-content/plugins/chinese-poem/poem.css

后记:

有一个很有名的开源项目:fortune-mode-zh,里面有丰富的诗词文件,很早之前,我托ubuntu论坛里大牛的福在一直在conky中使用着。最近在看PHP,干脆写成Wordpress的插件,第一次写插件,还有很多不足,慢慢改吧。