WordPress 唐诗宋词 插件

很早就用上这个插件了,侧边的毛主席语录就是这个插件输出的,这个插件就是唐诗宋词(chinese poem)

安装后直接在Widgets那就可以设置了,唐诗300首,宋诗100首,道德经,笑话集,论语,谚语,增广贤文,毛泽东诗词,毛泽东语录,太多了,其实也可以自己制作词库。

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

这样就可以每隔30分钟更新一次诗词,需要注意的是:使用该函数必须保证插件目录下的 “poem.tmp”文件全局可写(权限为666)。

使用以下的代码,将随机从tang300、song100、songproses三个文件中取出一首诗。

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

--------

首先说明一下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'));
?>

可用模块

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

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

------------------

如何制作词库:

网络上有很多拽言牛语,那么要是每天在blog上显示一句,拽就一个字。ok,首先选用 “2008最新的100句超牛的语言” 作为原料,按照下面的组识形式写入文件 “niuyu2008″ ,编码为UTF-8。

再牛b的肖邦,也弹不出老子的悲伤!
%
我左青龙,右白虎,肩膀纹个米老鼠。
%
秃驴,敢跟贫道抢师太?
%

改好后把 “niuyu2008″ 移到”唐诗宋词”插件的根目录下。使用支持UTF-8的编辑器打开文件 “poem-models.php” ,你会发现文件结尾有一段注释: /* Add-Ons 自定义模块 */ 就是这里了,在下面添加代码即可。

class niuyu2008 implements Poem_Inter {
public function format_poem($poem_src) {
$poem_array = preg_split(‘/\n/’ , $poem_src, -1, PREG_SPLIT_NO_EMPTY);
return $poem_array[0];
} //END func format_poem
} //END class niuyu2008
<?php
if (function_exists(show_chinese_poetry))
show_chinese_poetry(array('niuyu2008'), FALSE, 1440);
?>

----------

随机显示一条名言警句,并安置在Blog首页的浏览器标题栏

老样子,在文件 “poem-models.php” 最后的注释(/* Add-Ons 自定义模块 */)后面加入

/**
* wisdom: 名言警句
* 用于blog首页的浏览器标题栏显示
*/
class wisdom implements Poem_Inter {
/**
* @see Poem_Inter::format_poem()
*
* @param string $poem_src
*/
public function format_poem($poem_src) {
$poem_array = preg_split(‘/\n/’ , $poem_src, -1, PREG_SPLIT_NO_EMPTY);
$title_add = trim($poem_array[0]);
$js_code = ““;
return $js_code;
} //END func format_poem
} //END class wisdom

index.php

<?php
if (is_home() && function_exists(show_chinese_poem))
show_chinese_poem(array('wisdom'), FALSE);
?>

--------

随机显示图片

class image implements Poem_Inter {
public function format_poem($poem_src) {
$poem_array = preg_split(‘/\n/’ , $poem_src, -1, PREG_SPLIT_NO_EMPTY);
return “图片URL“;
} //END func format_poem
} //END class image

发表评论

电子邮件地址不会被公开。

 smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

无觅相关文章插件,快速提升流量